]> granicus.if.org Git - php/commitdiff
Fixed bug #76717
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 11 Mar 2019 14:35:02 +0000 (15:35 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 11 Mar 2019 14:35:02 +0000 (15:35 +0100)
Print INT_MIN as -INT_MAX-1 to avoid it getting parsed as a float
literal due to integer overflow.

NEWS
ext/standard/tests/general_functions/bug76717.phpt [new file with mode: 0644]
ext/standard/var.c

diff --git a/NEWS b/NEWS
index ffd0bacccb51540bd5f995f93b709cc607b36641..967fed2918ad412d54f4372cac79142b6c30d48c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,8 @@ PHP                                                                        NEWS
     custom wrapper). (Laruence)
   . Fixed bug #77669 (Crash in extract() when overwriting extracted array).
     (Nikita)
+  . Fixed bug #76717 (var_export() does not create a parsable value for
+    PHP_INT_MIN). (Nikita)
 
 07 Mar 2019, PHP 7.2.16
 
diff --git a/ext/standard/tests/general_functions/bug76717.phpt b/ext/standard/tests/general_functions/bug76717.phpt
new file mode 100644 (file)
index 0000000..b4bbd04
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #76717: var_export() does not create a parsable value for PHP_INT_MIN
+--FILE--
+<?php
+
+$min = eval('return '.var_export(PHP_INT_MIN, true).';');
+$max = eval('return '.var_export(PHP_INT_MAX, true).';');
+var_dump($min === PHP_INT_MIN);
+var_dump($max === PHP_INT_MAX);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
index a5a88b634dfe7d9744e999dc58b3a123b2c1bf29..030160561051cba0b630953a3998f409bb7ed322 100644 (file)
@@ -459,6 +459,13 @@ again:
                        smart_str_appendl(buf, "NULL", 4);
                        break;
                case IS_LONG:
+                       /* INT_MIN as a literal will be parsed as a float. Emit something like
+                        * -9223372036854775807-1 to avoid this. */
+                       if (Z_LVAL_P(struc) == ZEND_LONG_MIN) {
+                               smart_str_append_long(buf, ZEND_LONG_MIN+1);
+                               smart_str_appends(buf, "-1");
+                               break;
+                       }
                        smart_str_append_long(buf, Z_LVAL_P(struc));
                        break;
                case IS_DOUBLE: