summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--ext/json/JSON_parser.c7
-rw-r--r--ext/json/json.c14
-rw-r--r--ext/json/tests/pass001.1.phpt4
4 files changed, 12 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index 910ff24796..8f1ae9a6d6 100644
--- a/NEWS
+++ b/NEWS
@@ -89,6 +89,7 @@ PHP NEWS
- Fixed altering $this via argument named "this". (Dmitry)
- Fixed PHP CLI usage of php.ini from the binary location. (Hannes)
- Fixed segfault in strripos(). (Tony, Joxean Koret)
+- Fixed bug #41673 (json_encode breaks large numbers in arrays). (Ilia)
- Fixed bug #41525 (ReflectionParameter::getPosition() not available). (Marcus)
- Fixed bug #41511 (Compile failure under IRIX 6.5.30 building md5.c). (Jani)
- Fixed bug #41504 (json_decode() incorrectly decodes JSON arrays with empty
diff --git a/ext/json/JSON_parser.c b/ext/json/JSON_parser.c
index 2f2d268125..9f46553f67 100644
--- a/ext/json/JSON_parser.c
+++ b/ext/json/JSON_parser.c
@@ -284,7 +284,12 @@ static void json_create_zval(zval **z, smart_str *buf, int type)
if (type == IS_LONG)
{
- ZVAL_LONG(*z, atol(buf->c));
+ double d = zend_strtod(buf->c, NULL);
+ if (d > LONG_MAX) {
+ ZVAL_DOUBLE(*z, d);
+ } else {
+ ZVAL_LONG(*z, (long)d);
+ }
}
else if (type == IS_DOUBLE)
{
diff --git a/ext/json/json.c b/ext/json/json.c
index 737421f5ac..56507a2cbc 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -355,17 +355,9 @@ static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) {
if (!zend_isinf(dbl) && !zend_isnan(dbl)) {
len = spprintf(&d, 0, "%.*g", (int) EG(precision), dbl);
- if (d) {
- if (dbl > LONG_MAX && !memchr(d, '.', len)) {
- smart_str_append_unsigned(buf, (unsigned long)Z_DVAL_P(val));
- } else {
- smart_str_appendl(buf, d, len);
- }
- efree(d);
- }
- }
- else
- {
+ smart_str_appendl(buf, d, len);
+ efree(d);
+ } else {
zend_error(E_WARNING, "[json] (json_encode_r) double %.9g does not conform to the JSON spec, encoded as 0.", dbl);
smart_str_appendc(buf, '0');
}
diff --git a/ext/json/tests/pass001.1.phpt b/ext/json/tests/pass001.1.phpt
index 57a016b40b..828a6499f7 100644
--- a/ext/json/tests/pass001.1.phpt
+++ b/ext/json/tests/pass001.1.phpt
@@ -573,7 +573,7 @@ array(14) {
["_empty_"]=>
int(0)
["E no ."]=>
- int(4000000000000)
+ %s(4000000000000)
["zero"]=>
int(0)
["one"]=>
@@ -754,7 +754,7 @@ array(14) {
[""]=>
int(0)
["E no ."]=>
- int(4000000000000)
+ %s(4000000000000)
["zero"]=>
int(0)
["one"]=>