com php-src: Fix #78833: Integer overflow in pack causes out-of-bound access: NEWS ext/standard/pack.c ext/standard/tests/strings/bug78833.phpt

From: Date: Mon, 02 Dec 2019 10:18:19 +0000
Subject: com php-src: Fix #78833: Integer overflow in pack causes out-of-bound access: NEWS ext/standard/pack.c ext/standard/tests/strings/bug78833.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109344@lists.php.net to get a copy of this message
Commit: db420cb6a141876b2f7d101051fb01934a28071a Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 19 Nov 2019 14:22:26 +0100 Parents: c7141412ce4fba14dc33a8182cab7d84658ca613 Branches: PHP-7.2 PHP-7..3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=db420cb6a141876b2f7d101051fb01934a28071a Log: 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. Bugs: https://bugs.php.net/78833 Changed paths: M NEWS M ext/standard/pack.c A ext/standard/tests/strings/bug78833.phpt Diff: diff --git a/NEWS b/NEWS index c3d4783ebe8..8bb7aa5b1c1 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ PHP NEWS - Standard: . Fixed bug #78759 (array_search in $GLOBALS). (Nikita) + . Fixed bug #78833 (Integer overflow in pack causes out-of-bound access). + (cmb) 21 Nov 2019, PHP 7.2.25 diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 7d154841abe..b21edc4a84b 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -343,10 +343,13 @@ PHP_FUNCTION(pack) if (arg < 0) { arg = num_args - currentarg; } - + if (currentarg > INT_MAX - arg) { + goto too_few_args; + } currentarg += arg; if (currentarg > num_args) { +too_few_args: efree(formatcodes); efree(formatargs); php_error_docref(NULL, E_WARNING, "Type %c: too few arguments", code); diff --git a/ext/standard/tests/strings/bug78833.phpt b/ext/standard/tests/strings/bug78833.phpt new file mode 100644 index 00000000000..763b6ec4eac --- /dev/null +++ b/ext/standard/tests/strings/bug78833.phpt @@ -0,0 +1,9 @@ +--TEST-- +Bug #78833 (Integer overflow in pack causes out-of-bound access) +--FILE-- +<?php +var_dump(pack("E2E2147483647H*", 0x0, 0x0, 0x0)); +?> +--EXPECTF-- +Warning: pack(): Type E: too few arguments in %s on line %d +bool(false)

« previous php.cvs (#109344) next »