Skip to content

Commit 3d81c54

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #78833: Integer overflow in pack causes out-of-bound access
2 parents 1979c5d + db420cb commit 3d81c54

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ PHP NEWS
2626
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita)
2727
. Fixed bug #77638 (var_export'ing certain class instances segfaults). (cmb)
2828
. Fixed bug #78840 (imploding $GLOBALS crashes). (cmb)
29+
. Fixed bug #78833 (Integer overflow in pack causes out-of-bound access).
30+
(cmb)
2931

3032
21 Nov 2019, PHP 7.3.12
3133

ext/standard/pack.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,13 @@ PHP_FUNCTION(pack)
342342
if (arg < 0) {
343343
arg = num_args - currentarg;
344344
}
345-
345+
if (currentarg > INT_MAX - arg) {
346+
goto too_few_args;
347+
}
346348
currentarg += arg;
347349

348350
if (currentarg > num_args) {
351+
too_few_args:
349352
efree(formatcodes);
350353
efree(formatargs);
351354
php_error_docref(NULL, E_WARNING, "Type %c: too few arguments", code);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug #78833 (Integer overflow in pack causes out-of-bound access)
3+
--FILE--
4+
<?php
5+
var_dump(pack("E2E2147483647H*", 0x0, 0x0, 0x0));
6+
?>
7+
--EXPECTF--
8+
Warning: pack(): Type E: too few arguments in %s on line %d
9+
bool(false)

0 commit comments

Comments
 (0)