Skip to content

Commit 4ff242a

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #78833: Integer overflow in pack causes out-of-bound access
2 parents 67cd427 + 3d81c54 commit 4ff242a

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
@@ -27,6 +27,8 @@ PHP NEWS
2727
- Standard:
2828
. Fixed bug #77638 (var_export'ing certain class instances segfaults). (cmb)
2929
. Fixed bug #78840 (imploding $GLOBALS crashes). (cmb)
30+
. Fixed bug #78833 (Integer overflow in pack causes out-of-bound access).
31+
(cmb)
3032

3133
28 Nov 2019, PHP 7.4.0
3234

ext/standard/pack.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,13 @@ PHP_FUNCTION(pack)
347347
if (arg < 0) {
348348
arg = num_args - currentarg;
349349
}
350-
350+
if (currentarg > INT_MAX - arg) {
351+
goto too_few_args;
352+
}
351353
currentarg += arg;
352354

353355
if (currentarg > num_args) {
356+
too_few_args:
354357
efree(formatcodes);
355358
efree(formatargs);
356359
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)