Skip to content

Commit acb3e4d

Browse files
cmb69charmitro
authored andcommitted
Fix phpGH-17503: Undefined float conversion in mb_convert_variables
Conversion of floating point to integer values is undefined if the integral part of the float value cannot be represented by the integer type. We need to cater to that explicitly (in a manner similar to `zend_dval_to_lval_cap()`). Closes phpGH-17689.
1 parent 65cd46f commit acb3e4d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ PHP NEWS
1212
zend.exception_ignore_args=1 into account). (timwolla)
1313
. Fix fallback paths in fast_long_{add,sub}_function. (nielsdos)
1414

15+
- MBString:
16+
. Fixed bug GH-17503 (Undefined float conversion in mb_convert_variables).
17+
(cmb)
18+
1519
- Opcache:
1620
. Fixed bug GH-17654 (Multiple classes using same trait causes function
1721
JIT crash). (nielsdos)

ext/mbstring/mbstring.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3348,7 +3348,8 @@ try_next_encoding:;
33483348
}
33493349

33503350
for (size_t i = 0; i < length; i++) {
3351-
array[i].demerits *= array[i].multiplier;
3351+
double demerits = array[i].demerits * (double) array[i].multiplier;
3352+
array[i].demerits = demerits < (double) UINT64_MAX ? (uint64_t) demerits : UINT64_MAX;
33523353
}
33533354

33543355
return length;

ext/mbstring/tests/gh17503.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-17503 (Undefined float conversion in mb_convert_variables)
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
$a = array_fill(0, 500, "<blah>");
8+
var_dump(mb_convert_variables("ASCII", ["UTF-8", "UTF-16"], $a));
9+
?>
10+
--EXPECT--
11+
string(5) "UTF-8"

0 commit comments

Comments
 (0)