Skip to content

Commit 048cc9b

Browse files
committed
Convert unpack offset warning to ValueError
1 parent d893404 commit 048cc9b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ext/standard/pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,10 @@ PHP_FUNCTION(unpack)
731731

732732

733733
if (offset < 0 || offset > inputlen) {
734-
php_error_docref(NULL, E_WARNING, "Offset " ZEND_LONG_FMT " is out of input range" , offset);
735-
RETURN_FALSE;
734+
zend_argument_value_error(3, "must be contained in argument #2 ($data)");
735+
RETURN_THROWS();
736736
}
737+
737738
input += offset;
738739
inputlen -= offset;
739740

ext/standard/tests/strings/unpack_offset.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@ printf("0x%08x 0x%08x\n", $a[1], $a[2]);
1010
printf("0x%08x 0x%08x\n",
1111
unpack("l", $data, 3)[1],
1212
unpack("@4/l", $data, 3)[1]);
13+
14+
try {
15+
unpack("l", "foo", 10);
16+
} catch (ValueError $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
try {
20+
unpack("l", "foo", -1);
21+
} catch (ValueError $e) {
22+
echo $e->getMessage(), "\n";
23+
}
1324
?>
1425
--EXPECT--
1526
0x01020304 0x05060708
1627
0x01020304 0x05060708
28+
unpack(): Argument #3 ($offset) must be contained in argument #2 ($data)
29+
unpack(): Argument #3 ($offset) must be contained in argument #2 ($data)

0 commit comments

Comments
 (0)