Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ext/standard/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,13 @@ PHP_FUNCTION(unpack)
zend_string *buf;
zend_long ipos, opos;


if (size > INT_MAX / 2) {
zend_string_release(real_name);
zend_argument_value_error(1, "repeater must be less than or equal to %d", INT_MAX / 2);
RETURN_THROWS();
}

/* If size was given take minimum of len and size */
if (size >= 0 && len > (size * 2)) {
len = size * 2;
Expand Down
25 changes: 25 additions & 0 deletions ext/standard/tests/strings/gh15613.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
GH-15613 overflow on hex strings repeater value
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64 bit platform only");
?>
--INI--
memory_limit=-1
--FILE--
<?php
try {
unpack('h2147483647', str_repeat('X', 2**31 + 10));
} catch (\ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}

try {
unpack('H2147483647', str_repeat('X', 2**31 + 10));
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
unpack(): Argument #1 ($format) repeater must be less than or equal to %d
unpack(): Argument #1 ($format) repeater must be less than or equal to %d
Loading