mirror of
https://github.com/php/php-src.git
synced 2025-08-17 22:48:57 +02:00
Fix #66797: mb_substr only takes 32-bit signed integer
`from` and `len` are `long`, but get passed to mbfl_substr() which expects `int`s. Therefore we clamp the values to avoid the undefined conversion behavior.
This commit is contained in:
parent
af7828a20f
commit
2f10db36af
3 changed files with 33 additions and 0 deletions
3
NEWS
3
NEWS
|
@ -31,6 +31,9 @@ PHP NEWS
|
|||
- JSON:
|
||||
. Fixed bug #72787 (json_decode reads out of bounds). (Jakub Zelenka)
|
||||
|
||||
- mbstring:
|
||||
. Fixed bug #66797 (mb_substr only takes 32-bit signed integer). (cmb)
|
||||
|
||||
- MSSQL:
|
||||
. Fixed bug #72039 (Use of uninitialised value on mssql_guid_string). (Kalle)
|
||||
|
||||
|
|
|
@ -2799,6 +2799,13 @@ PHP_FUNCTION(mb_substr)
|
|||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (from > INT_MAX) {
|
||||
from = INT_MAX;
|
||||
}
|
||||
if (len > INT_MAX) {
|
||||
len = INT_MAX;
|
||||
}
|
||||
|
||||
ret = mbfl_substr(&string, &result, from, len);
|
||||
if (NULL == ret) {
|
||||
RETURN_FALSE;
|
||||
|
|
23
ext/mbstring/tests/bug66797.phpt
Normal file
23
ext/mbstring/tests/bug66797.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--TEST--
|
||||
Bug #66797 (mb_substr only takes 32-bit signed integer)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
|
||||
if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(
|
||||
mb_substr('bar', 0, 0x7fffffff),
|
||||
mb_substr('bar', 0, 0x80000000),
|
||||
mb_substr('bar', 0xffffffff, 1),
|
||||
mb_substr('bar', 0x100000000, 1)
|
||||
);
|
||||
?>
|
||||
==DONE==
|
||||
--EXPECTF--
|
||||
string(3) "bar"
|
||||
string(3) "bar"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
==DONE==
|
Loading…
Add table
Add a link
Reference in a new issue