Skip to content

Commit 1fd32e9

Browse files
committed
Fixed bug #76717
Print INT_MIN as -INT_MAX-1 to avoid it getting parsed as a float literal due to integer overflow.
1 parent 769d2d9 commit 1fd32e9

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ PHP NEWS
3737
custom wrapper). (Laruence)
3838
. Fixed bug #77669 (Crash in extract() when overwriting extracted array).
3939
(Nikita)
40+
. Fixed bug #76717 (var_export() does not create a parsable value for
41+
PHP_INT_MIN). (Nikita)
4042

4143
07 Mar 2019, PHP 7.2.16
4244

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #76717: var_export() does not create a parsable value for PHP_INT_MIN
3+
--FILE--
4+
<?php
5+
6+
$min = eval('return '.var_export(PHP_INT_MIN, true).';');
7+
$max = eval('return '.var_export(PHP_INT_MAX, true).';');
8+
var_dump($min === PHP_INT_MIN);
9+
var_dump($max === PHP_INT_MAX);
10+
11+
?>
12+
--EXPECT--
13+
bool(true)
14+
bool(true)

ext/standard/var.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
459459
smart_str_appendl(buf, "NULL", 4);
460460
break;
461461
case IS_LONG:
462+
/* INT_MIN as a literal will be parsed as a float. Emit something like
463+
* -9223372036854775807-1 to avoid this. */
464+
if (Z_LVAL_P(struc) == ZEND_LONG_MIN) {
465+
smart_str_append_long(buf, ZEND_LONG_MIN+1);
466+
smart_str_appends(buf, "-1");
467+
break;
468+
}
462469
smart_str_append_long(buf, Z_LVAL_P(struc));
463470
break;
464471
case IS_DOUBLE:

0 commit comments

Comments
 (0)