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),
/* 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 {}
/* 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)
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)
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);
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) {
#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':
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;
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 */
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) {
Bug #78833 (Integer overflow in pack causes out-of-bound access)
--FILE--
<?php
-var_dump(pack("E2E2147483647H*", 0x0, 0x0, 0x0));
+try {
+ var_dump(pack("E2E2147483647H*", 0x0, 0x0, 0x0));
+} catch (ValueError $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
-Warning: pack(): Type E: too few arguments in %s on line %d
-bool(false)
+--EXPECT--
+Type E: too few arguments
?>
--FILE--
<?php
-var_dump(pack("Q", 0));
-var_dump(pack("J", 0));
-var_dump(pack("P", 0));
-var_dump(pack("q", 0));
+try {
+ var_dump(pack("Q", 0));
+} catch (ValueError $e) {
+ echo $e->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
+++ /dev/null
---TEST--
-Invalid format type validation
---FILE--
-<?php
- var_dump(unpack("-2222", 1));
- echo "Done\n";
-?>
---EXPECTF--
-Warning: unpack(): Invalid format type - in %sunpack.php on line %d
-bool(false)
-Done
--FILE--
<?php
-echo "*** Testing unpack() : error conditions ***\n";
+try {
+ var_dump(unpack("B", pack("I", 65534)));
+} catch (ValueError $e) {
+ echo $e->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