mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
MFH Fix bug #47644 - Valid integers are truncated with json_decode()
This commit is contained in:
parent
1d5dbea704
commit
07e675cc52
2 changed files with 47 additions and 4 deletions
|
@ -289,11 +289,11 @@ static void json_create_zval(zval **z, smart_str *buf, int type)
|
|||
|
||||
if (type == IS_LONG)
|
||||
{
|
||||
double d = zend_strtod(buf->c, NULL);
|
||||
if (d > LONG_MAX || d < LONG_MIN) {
|
||||
ZVAL_DOUBLE(*z, d);
|
||||
long l = strtol(buf->c, NULL, 10);
|
||||
if (l > LONG_MAX || l < LONG_MIN) {
|
||||
ZVAL_DOUBLE(*z, zend_strtod(buf->c, NULL));
|
||||
} else {
|
||||
ZVAL_LONG(*z, (long)d);
|
||||
ZVAL_LONG(*z, l);
|
||||
}
|
||||
}
|
||||
else if (type == IS_DOUBLE)
|
||||
|
|
43
ext/json/tests/bug47644.phpt
Normal file
43
ext/json/tests/bug47644.phpt
Normal file
|
@ -0,0 +1,43 @@
|
|||
--TEST--
|
||||
Bug #47644 (valid large integers are truncated)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('json')) die('skip: json extension not available');
|
||||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
for ($i = 10000000000000000; $i < 10000000000000006; $i++) {
|
||||
var_dump(json_decode("[$i]"));
|
||||
}
|
||||
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(10000000000000000)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(10000000000000001)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(10000000000000002)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(10000000000000003)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(10000000000000004)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(10000000000000005)
|
||||
}
|
||||
Done
|
Loading…
Add table
Add a link
Reference in a new issue