mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Convert unpack offset warning to ValueError
This commit is contained in:
parent
d893404fb9
commit
048cc9ba78
2 changed files with 16 additions and 2 deletions
|
@ -731,9 +731,10 @@ PHP_FUNCTION(unpack)
|
||||||
|
|
||||||
|
|
||||||
if (offset < 0 || offset > inputlen) {
|
if (offset < 0 || offset > inputlen) {
|
||||||
php_error_docref(NULL, E_WARNING, "Offset " ZEND_LONG_FMT " is out of input range" , offset);
|
zend_argument_value_error(3, "must be contained in argument #2 ($data)");
|
||||||
RETURN_FALSE;
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
input += offset;
|
input += offset;
|
||||||
inputlen -= offset;
|
inputlen -= offset;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,20 @@ printf("0x%08x 0x%08x\n", $a[1], $a[2]);
|
||||||
printf("0x%08x 0x%08x\n",
|
printf("0x%08x 0x%08x\n",
|
||||||
unpack("l", $data, 3)[1],
|
unpack("l", $data, 3)[1],
|
||||||
unpack("@4/l", $data, 3)[1]);
|
unpack("@4/l", $data, 3)[1]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
unpack("l", "foo", 10);
|
||||||
|
} catch (ValueError $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
unpack("l", "foo", -1);
|
||||||
|
} catch (ValueError $e) {
|
||||||
|
echo $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
0x01020304 0x05060708
|
0x01020304 0x05060708
|
||||||
0x01020304 0x05060708
|
0x01020304 0x05060708
|
||||||
|
unpack(): Argument #3 ($offset) must be contained in argument #2 ($data)
|
||||||
|
unpack(): Argument #3 ($offset) must be contained in argument #2 ($data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue