diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 936e8a8915ff4..e3b4da720c4d1 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -324,7 +324,7 @@ static const func_info_t func_infos[] = { F1("realpath", MAY_BE_FALSE | MAY_BE_STRING), F1("fsockopen", MAY_BE_FALSE | MAY_BE_RESOURCE), FN("pfsockopen", MAY_BE_FALSE | MAY_BE_RESOURCE), - F1("pack", MAY_BE_FALSE | MAY_BE_STRING), + F1("pack", MAY_BE_STRING), F1("unpack", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY), F1("get_browser", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_OBJECT | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY), F1("crypt", MAY_BE_STRING), diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 0bc7bd8aef754..58f09ca2a19ba 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -1134,7 +1134,7 @@ function getrusage(int $who = 0): array|false {} /* pack.c */ -function pack(string $format, mixed ...$args): string|false {} +function pack(string $format, mixed ...$args): string {} function unpack(string $format, string $data, int $offset = 0): array|false {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 6aff74adcfd3a..1c90803d96dff 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 3c02183529eed2eb21d801ed2ba615deaf749b1d */ + * Stub hash: f029ab7f1d9fa2a99a5612a928d0b731de6aaeed */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) @@ -1747,10 +1747,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_getrusage, 0, 0, MAY_BE_ARRAY|MA ZEND_END_ARG_INFO() #endif -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pack, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, format, IS_STRING, 0) - ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0) -ZEND_END_ARG_INFO() +#define arginfo_pack arginfo_sprintf ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_unpack, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, format, IS_STRING, 0) diff --git a/ext/standard/pack.c b/ext/standard/pack.c index bbae59c6ae9c0..bfa6708f66d86 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -47,8 +47,8 @@ if ((a) < 0 || ((INT_MAX - outputpos)/((int)b)) < (a)) { \ efree(formatcodes); \ efree(formatargs); \ - php_error_docref(NULL, E_WARNING, "Type %c: integer overflow in format string", code); \ - RETURN_FALSE; \ + zend_value_error("Type %c: integer overflow in format string", code); \ + RETURN_THROWS(); \ } \ outputpos += (a)*(b); @@ -282,8 +282,8 @@ PHP_FUNCTION(pack) if (currentarg >= num_args) { efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "Type %c: not enough arguments", code); - RETURN_FALSE; + zend_value_error("Type %c: not enough arguments", code); + RETURN_THROWS(); } if (arg < 0) { @@ -313,8 +313,8 @@ PHP_FUNCTION(pack) #if SIZEOF_ZEND_LONG < 8 efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "64-bit format codes are not available for 32-bit versions of PHP"); - RETURN_FALSE; + zend_value_error("64-bit format codes are not available for 32-bit versions of PHP"); + RETURN_THROWS(); #endif case 'c': case 'C': @@ -346,16 +346,16 @@ PHP_FUNCTION(pack) too_few_args: efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "Type %c: too few arguments", code); - RETURN_FALSE; + zend_value_error("Type %c: too few arguments", code); + RETURN_THROWS(); } break; default: efree(formatcodes); efree(formatargs); - php_error_docref(NULL, E_WARNING, "Type %c: unknown format code", code); - RETURN_FALSE; + zend_value_error("Type %c: unknown format code", code); + RETURN_THROWS(); } formatcodes[formatcount] = code; @@ -845,9 +845,9 @@ PHP_FUNCTION(unpack) size = 8; break; #else - php_error_docref(NULL, E_WARNING, "64-bit format codes are not available for 32-bit versions of PHP"); + zend_value_error("64-bit format codes are not available for 32-bit versions of PHP"); zend_array_destroy(Z_ARR_P(return_value)); - RETURN_FALSE; + RETURN_THROWS(); #endif /* Use sizeof(float) bytes of input */ @@ -865,10 +865,9 @@ PHP_FUNCTION(unpack) break; default: - php_error_docref(NULL, E_WARNING, "Invalid format type %c", type); + zend_value_error("Invalid format type %c", type); zend_array_destroy(Z_ARR_P(return_value)); - RETURN_FALSE; - break; + RETURN_THROWS(); } if (size != 0 && size != -1 && size < 0) { diff --git a/ext/standard/tests/strings/bug78833.phpt b/ext/standard/tests/strings/bug78833.phpt index 763b6ec4eac32..7712e133facec 100644 --- a/ext/standard/tests/strings/bug78833.phpt +++ b/ext/standard/tests/strings/bug78833.phpt @@ -2,8 +2,11 @@ Bug #78833 (Integer overflow in pack causes out-of-bound access) --FILE-- getMessage(), "\n"; +} ?> ---EXPECTF-- -Warning: pack(): Type E: too few arguments in %s on line %d -bool(false) +--EXPECT-- +Type E: too few arguments diff --git a/ext/standard/tests/strings/pack64_32.phpt b/ext/standard/tests/strings/pack64_32.phpt index 978e04449de61..87e945c5fac66 100644 --- a/ext/standard/tests/strings/pack64_32.phpt +++ b/ext/standard/tests/strings/pack64_32.phpt @@ -8,37 +8,55 @@ if (PHP_INT_SIZE > 4) { ?> --FILE-- getMessage(), "\n"; +} +try { + var_dump(pack("J", 0)); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(pack("P", 0)); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(pack("q", 0)); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + +try { + var_dump(unpack("Q", '')); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(unpack("J", '')); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(unpack("P", '')); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(unpack("q", '')); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} -var_dump(unpack("Q", '')); -var_dump(unpack("J", '')); -var_dump(unpack("P", '')); -var_dump(unpack("q", '')); ?> --EXPECTF-- -Warning: pack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) - -Warning: pack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) - -Warning: pack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) - -Warning: pack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) - -Warning: unpack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) - -Warning: unpack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) - -Warning: unpack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) - -Warning: unpack(): 64-bit format codes are not available for 32-bit versions of PHP in %s on line %d -bool(false) +64-bit format codes are not available for 32-bit versions of PHP +64-bit format codes are not available for 32-bit versions of PHP +64-bit format codes are not available for 32-bit versions of PHP +64-bit format codes are not available for 32-bit versions of PHP +64-bit format codes are not available for 32-bit versions of PHP +64-bit format codes are not available for 32-bit versions of PHP +64-bit format codes are not available for 32-bit versions of PHP +64-bit format codes are not available for 32-bit versions of PHP diff --git a/ext/standard/tests/strings/unpack.phpt b/ext/standard/tests/strings/unpack.phpt deleted file mode 100644 index 435361cca54a6..0000000000000 --- a/ext/standard/tests/strings/unpack.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Invalid format type validation ---FILE-- - ---EXPECTF-- -Warning: unpack(): Invalid format type - in %sunpack.php on line %d -bool(false) -Done diff --git a/ext/standard/tests/strings/unpack_error.phpt b/ext/standard/tests/strings/unpack_error.phpt index 5da3cee273372..c41185b23acef 100644 --- a/ext/standard/tests/strings/unpack_error.phpt +++ b/ext/standard/tests/strings/unpack_error.phpt @@ -3,16 +3,12 @@ Test unpack() function : error conditions --FILE-- getMessage(), "\n"; +} -echo "\n-- Testing unpack() function with invalid format character --\n"; -$extra_arg = 10; -var_dump(unpack("B", pack("I", 65534))); ?> ---EXPECTF-- -*** Testing unpack() : error conditions *** - --- Testing unpack() function with invalid format character -- - -Warning: unpack(): Invalid format type B in %s on line %d -bool(false) +--EXPECT-- +Invalid format type B