diff options
-rw-r--r-- | ext/standard/pack.c | 5 | ||||
-rw-r--r-- | ext/standard/tests/strings/bug78833.phpt | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 8f47aac258..c3bcf8d2e6 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -345,10 +345,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 0000000000..763b6ec4ea --- /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) |