com php-src: Fixed bug #76717: NEWS ext/standard/tests/general _functions/bug76717.phpt ext/standard/var.c
| From: | Nikita Popov | Date: | Mon, 11 Mar 2019 14:35:02 +0000 |
| Subject: | com php-src: Fixed bug #76717: NEWS ext/standard/tests/general _functions/bug76717.phpt ext/standard/var.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-105080@lists.php.net to get a copy of this message | ||
Commit: 1fd32e9c2f15eabdc7e531b1fa76f62fc5a8ca75
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 11 Mar 2019 15:35:02 +0100
Parents: 769d2d9b62acfa5ed12acc758177ab8d64439e79
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1fd32e9c2f15eabdc7e531b1fa76f62fc5a8ca75
Log:
Fixed bug #76717
Print INT_MIN as -INT_MAX-1 to avoid it getting parsed as a float
literal due to integer overflow.
Bugs:
https://bugs.php.net/76717
Changed paths:
M NEWS
A ext/standard/tests/general_functions/bug76717.phpt
M ext/standard/var.c
Diff:
diff --git a/NEWS b/NEWS
index ffd0bac..967fed2 100644
--- 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
index 0000000..b4bbd04
--- /dev/null
+++ b/ext/standard/tests/general_functions/bug76717.phpt
@@ -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)
diff --git a/ext/standard/var.c b/ext/standard/var.c
index a5a88b6..0301605 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -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: