From 17530bbccd84f437efafa731edc81b442817f185 Mon Sep 17 00:00:00 2001 From: Scott MacVicar Date: Tue, 17 Mar 2009 02:02:45 +0000 Subject: [PATCH] MFH Fix bug #47644 - Valid integers are truncated with json_decode() --- ext/json/JSON_parser.c | 12 +++++----- ext/json/tests/bug47644.phpt | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 ext/json/tests/bug47644.phpt diff --git a/ext/json/JSON_parser.c b/ext/json/JSON_parser.c index a88dde9fa7..6eca7ad7c1 100644 --- a/ext/json/JSON_parser.c +++ b/ext/json/JSON_parser.c @@ -284,12 +284,12 @@ 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); - } else { - ZVAL_LONG(*z, (long)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, l); + } } else if (type == IS_DOUBLE) { diff --git a/ext/json/tests/bug47644.phpt b/ext/json/tests/bug47644.phpt new file mode 100644 index 0000000000..5e996b6973 --- /dev/null +++ b/ext/json/tests/bug47644.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #47644 (valid large integers are truncated) +--SKIPIF-- + +--FILE-- + +--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 -- 2.40.0