Skip to content
Permalink
Browse files

Fixed bug #76717

Print INT_MIN as -INT_MAX-1 to avoid it getting parsed as a float
literal due to integer overflow.
  • Loading branch information...
nikic committed Mar 11, 2019
1 parent 769d2d9 commit 1fd32e9c2f15eabdc7e531b1fa76f62fc5a8ca75
Showing with 23 additions and 0 deletions.
  1. +2 −0 NEWS
  2. +14 −0 ext/standard/tests/general_functions/bug76717.phpt
  3. +7 −0 ext/standard/var.c
2 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

@@ -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)
@@ -459,6 +459,13 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
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:

6 comments on commit 1fd32e9

@remicollet

This comment has been minimized.

Copy link
Contributor

replied Mar 19, 2019

Looks like this break ext/standard/tests/general_functions/var_export_basic1.phpt on 32-bit

061+ -2147483647-1
062+ -2147483647-1
063+ string(13) "-2147483647-1"
061- -2147483648
062- -2147483648
063- string(11) "-2147483648"
086+ -2147483647-1
087+ -2147483647-1
088+ string(13) "-2147483647-1"
086- -2147483648
087- -2147483648
088- string(11) "-2147483648"

This seems to be expected, @nikic can you please check ?

@nikic

This comment has been minimized.

Copy link
Member Author

replied Mar 19, 2019

Yeah, those results are expected, the test expectation just needs to be changed.

@remicollet

This comment has been minimized.

Copy link
Contributor

replied Mar 19, 2019

Also ext/standard/tests/general_functions/var_export-locale.phpt

072+ -2147483647-1
073+ -2147483647-1
074+ string(13) "-2147483647-1"
072- -2147483648
073- -2147483648
074- string(11) "-2147483648"
102+ -2147483647-1
103+ -2147483647-1
104+ string(13) "-2147483647-1"
102- -2147483648
103- -2147483648
104- string(11) "-2147483648"

@remicollet

This comment has been minimized.

Copy link
Contributor

replied Mar 19, 2019

@nikic thanks for confirming.

I will add a skip condition for 32-bit on those 2 tests (and probably duplicate them for 32-bit which have different output).

@remicollet

This comment has been minimized.

Copy link
Contributor

replied Mar 20, 2019

Tests fixed in a467a89

@nikic

This comment has been minimized.

Copy link
Member Author

replied Mar 20, 2019

Thanks!

Please sign in to comment.
You can’t perform that action at this time.