1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-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 GH-17689.
This commit is contained in:
Christoph M. Becker
2025-02-04 12:13:24 +01:00
parent 88e1917cb7
commit 55e676e181
3 changed files with 17 additions and 1 deletions

4
NEWS
View File

@@ -12,6 +12,10 @@ PHP NEWS
zend.exception_ignore_args=1 into account). (timwolla)
. Fix fallback paths in fast_long_{add,sub}_function. (nielsdos)
- MBString:
. Fixed bug GH-17503 (Undefined float conversion in mb_convert_variables).
(cmb)
- Opcache:
. Fixed bug GH-17654 (Multiple classes using same trait causes function
JIT crash). (nielsdos)

View File

@@ -3092,7 +3092,8 @@ try_next_encoding:;
}
for (size_t i = 0; i < length; i++) {
array[i].demerits *= array[i].multiplier;
double demerits = array[i].demerits * (double) array[i].multiplier;
array[i].demerits = demerits < (double) UINT64_MAX ? (uint64_t) demerits : UINT64_MAX;
}
return length;

View File

@@ -0,0 +1,11 @@
--TEST--
GH-17503 (Undefined float conversion in mb_convert_variables)
--EXTENSIONS--
mbstring
--FILE--
<?php
$a = array_fill(0, 500, "<blah>");
var_dump(mb_convert_variables("ASCII", ["UTF-8", "UTF-16"], $a));
?>
--EXPECT--
string(5) "UTF-8"