]> granicus.if.org Git - php/commitdiff
Fixed bug #68044: Integer overflow in unserialize() (32-bits only)
authorStanislav Malyshev <stas@php.net>
Sun, 28 Sep 2014 21:19:31 +0000 (14:19 -0700)
committerStanislav Malyshev <stas@php.net>
Tue, 14 Oct 2014 17:51:24 +0000 (10:51 -0700)
ext/standard/tests/serialize/bug68044.phpt [new file with mode: 0644]
ext/standard/var_unserializer.c
ext/standard/var_unserializer.re

diff --git a/ext/standard/tests/serialize/bug68044.phpt b/ext/standard/tests/serialize/bug68044.phpt
new file mode 100644 (file)
index 0000000..031e44e
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #68044 Integer overflow in unserialize() (32-bits only)
+--FILE--
+<?php
+       echo unserialize('C:3:"XYZ":18446744075857035259:{}');
+?>
+===DONE==
+--EXPECTF--
+Warning: Insufficient data for unserializing - %d required, 1 present in %s/bug68044.php on line 2
+
+Notice: unserialize(): Error at offset 32 of 33 bytes in %s/bug68044.php on line 2
+===DONE==
index c94f3eec5843b59a11a8bd2fe64a9899b28673e5..9be2b0658a01e8eef0cdffcbdb70230b8f3e6be2 100644 (file)
@@ -386,7 +386,7 @@ static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
 
        (*p) += 2;
 
-       if (datalen < 0 || (*p) + datalen >= max) {
+       if (datalen < 0 || (max - (*p)) <= datalen) {
                zend_error(E_WARNING, "Insufficient data for unserializing - %pd required, %pd present", datalen, (zend_long)(max - (*p)));
                return 0;
        }
index a11f556f7eabe435dec194c3f61e3c35606b669a..1898c7734c8c849506c95dacc79ca116e93e197d 100644 (file)
@@ -390,7 +390,7 @@ static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
 
        (*p) += 2;
 
-       if (datalen < 0 || (*p) + datalen >= max) {
+       if (datalen < 0 || (max - (*p)) <= datalen) {
                zend_error(E_WARNING, "Insufficient data for unserializing - %pd required, %pd present", datalen, (zend_long)(max - (*p)));
                return 0;
        }