]> granicus.if.org Git - php/commitdiff
Convert unpack offset warning to ValueError
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 12:00:48 +0000 (14:00 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 12:13:26 +0000 (14:13 +0200)
ext/standard/pack.c
ext/standard/tests/strings/unpack_offset.phpt

index 013173dc7386acf5fd5513dcf291006ec45ad481..bbae59c6ae9c0ef8276b1daf393fb4df4d0bc2ee 100644 (file)
@@ -731,9 +731,10 @@ PHP_FUNCTION(unpack)
 
 
        if (offset < 0 || offset > inputlen) {
-               php_error_docref(NULL, E_WARNING, "Offset " ZEND_LONG_FMT " is out of input range" , offset);
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be contained in argument #2 ($data)");
+               RETURN_THROWS();
        }
+
        input += offset;
        inputlen -= offset;
 
index 451dd367246b0a957236b7fc303be17c880776f1..bd787859c11affd2e07c2ca1d511d55192d8f396 100644 (file)
@@ -10,7 +10,20 @@ printf("0x%08x 0x%08x\n", $a[1], $a[2]);
 printf("0x%08x 0x%08x\n",
     unpack("l", $data, 3)[1],
     unpack("@4/l", $data, 3)[1]);
+
+try {
+    unpack("l", "foo", 10);
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}
+try {
+    unpack("l", "foo", -1);
+} catch (ValueError $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
 --EXPECT--
 0x01020304 0x05060708
 0x01020304 0x05060708
+unpack(): Argument #3 ($offset) must be contained in argument #2 ($data)
+unpack(): Argument #3 ($offset) must be contained in argument #2 ($data)