From c34806e1455a8b28ff1df0850a05e204acbc2316 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 19 Apr 2007 23:21:22 +0000 Subject: [PATCH] Fixed bug #41121 (range() overflow handling for large numbers on 32bit machines). --- NEWS | 2 + ext/standard/array.c | 18 ++-- ext/standard/tests/array/bug41121.phpt | 125 +++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 ext/standard/tests/array/bug41121.phpt diff --git a/NEWS b/NEWS index 93e4f6cedb..ffb020a58a 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? Apr 2007, PHP 5.2.2RC2 - Upgraded SQLite 3 to version 3.3.16 (Ilia) +- Fixed bug #41121 (range() overflow handling for large numbers on 32bit + machines). (Ilia) - Fixed bug #41109 (recursiveiterator.inc says "implements" Iterator instead of "extends"). (Marcus) - Fixed bug #41093 (magic_quotes_gpc ignores first arrays keys). (Arpad, Ilia) diff --git a/ext/standard/array.c b/ext/standard/array.c index 3ff80a12a3..1e868e0488 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1718,13 +1718,13 @@ double_str: add_next_index_double(return_value, low); } } else { - int low, high; + double low, high; long lstep; long_str: - convert_to_long(zlow); - convert_to_long(zhigh); - low = Z_LVAL_P(zlow); - high = Z_LVAL_P(zhigh); + convert_to_double(zlow); + convert_to_double(zhigh); + low = Z_DVAL_P(zlow); + high = Z_DVAL_P(zhigh); lstep = (long) step; if (low > high) { /* Negative steps */ @@ -1733,18 +1733,18 @@ long_str: goto err; } for (; low >= high; low -= lstep) { - add_next_index_long(return_value, low); + add_next_index_long(return_value, (long)low); } - } else if (high > low) { /* Positive steps */ + } else if (high > low) { /* Positive steps */ if (high - low < lstep || lstep <= 0) { err = 1; goto err; } for (; low <= high; low += lstep) { - add_next_index_long(return_value, low); + add_next_index_long(return_value, (long)low); } } else { - add_next_index_long(return_value, low); + add_next_index_long(return_value, (long)low); } } err: diff --git a/ext/standard/tests/array/bug41121.phpt b/ext/standard/tests/array/bug41121.phpt new file mode 100644 index 0000000000..4cd188ddca --- /dev/null +++ b/ext/standard/tests/array/bug41121.phpt @@ -0,0 +1,125 @@ +--TEST-- +Bug #41121 (range() overflow handling for large numbers on 32bit machines) +--SKIPIF-- +--FILE-- + high +var_dump(range(2147483647, 2147483645, 1 )); +var_dump(range(2147483648, 2147483645, 1 )); + +?> +--EXPECT-- +array(3) { + [0]=> + int(2147483400) + [1]=> + int(2147483500) + [2]=> + int(2147483600) +} +array(3) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) +} +array(12) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) + [3]=> + float(2147483649) + [4]=> + float(2147483650) + [5]=> + float(2147483651) + [6]=> + float(2147483652) + [7]=> + float(2147483653) + [8]=> + float(2147483654) + [9]=> + float(2147483655) + [10]=> + float(2147483656) + [11]=> + float(2147483657) +} +array(4) { + [0]=> + int(2147483630) + [1]=> + int(2147483635) + [2]=> + int(2147483640) + [3]=> + int(2147483645) +} +array(4) { + [0]=> + float(-2147483645) + [1]=> + float(-2147483646) + [2]=> + float(-2147483647) + [3]=> + float(-2147483648) +} +array(5) { + [0]=> + float(-2147483645) + [1]=> + float(-2147483646) + [2]=> + float(-2147483647) + [3]=> + float(-2147483648) + [4]=> + float(-2147483649) +} +array(4) { + [0]=> + int(-2147483630) + [1]=> + int(-2147483635) + [2]=> + int(-2147483640) + [3]=> + int(-2147483645) +} +array(3) { + [0]=> + int(2147483647) + [1]=> + int(2147483646) + [2]=> + int(2147483645) +} +array(4) { + [0]=> + float(2147483648) + [1]=> + float(2147483647) + [2]=> + float(2147483646) + [3]=> + float(2147483645) +} -- 2.50.1