Skip to content

Commit db420cb

Browse files
committed
Fix #78833: Integer overflow in pack causes out-of-bound access
We check for potential signed integer overflow, and bail out gracefully, in that case.
1 parent c714141 commit db420cb

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
@@ -14,6 +14,8 @@ PHP NEWS
1414

1515
- Standard:
1616
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita)
17+
. Fixed bug #78833 (Integer overflow in pack causes out-of-bound access).
18+
(cmb)
1719

1820
21 Nov 2019, PHP 7.2.25
1921

ext/standard/pack.c

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

349351
if (currentarg > num_args) {
352+
too_few_args:
350353
efree(formatcodes);
351354
efree(formatargs);
352355
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)