[Tarantool-patches] [PATCH luajit] Limit exponent range in number parsing.
Sergey Kaplun
skaplun at tarantool.org
Thu Jan 25 13:06:32 MSK 2024
Hi, Sergey!
Thanks for the review!
Fixed you comment, see the patch below.
Branch is force-pushed.
On 25.01.24, Sergey Bronnikov wrote:
> Hi, Sergey!
>
> thanks for the patch!
>
>
> On 1/24/24 00:14, Sergey Kaplun wrote:
>
>
> <snipped>
>
> > +++ b/test/tarantool-tests/lj-788-limit-exponents-range.test.lua
> > @@ -0,0 +1,29 @@
> > +local tap = require('tap')
> > +
> > +-- Test file to demonstrate incorrect behaviour of exponent number
> > +-- form parsing.
> > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/788.
> > +local test = tap.test('lj-788-limit-exponents-range')
> > +test:plan(2)
> > +
> > +-- Before the patch, the powers greater than (1 << 16) * 10
> > +-- (655360) were parsed incorrectly. After the patch, powers
> > +-- greater than 1 << 20 (1048576 `STRSCAN_MAXEXP`) are considered
> > +-- invalid. See <src/lj_strscan.c> for details.
> > +-- Choose the first value between these values and the second
> > +-- value bigger than `STRSCAN_MAXEXP` to check parsing correctness
>
> typical values on testing boundaries [1] are: value before the boundary,
>
> boundary value and value after the boundary. So I propose to test these
> three values.
>
> 1: https://en.wikipedia.org/wiki/Boundary-value_analysis
Thanks! Good to know:).
I added the boundary test case and updated tests names as you suggested.
===================================================================
diff --git a/test/tarantool-tests/lj-788-limit-exponents-range.test.lua b/test/tarantool-tests/lj-788-limit-exponents-range.test.lua
index 8ab31600..0af584fd 100644
--- a/test/tarantool-tests/lj-788-limit-exponents-range.test.lua
+++ b/test/tarantool-tests/lj-788-limit-exponents-range.test.lua
@@ -4,7 +4,7 @@ local tap = require('tap')
-- form parsing.
-- See also: https://github.com/LuaJIT/LuaJIT/issues/788.
local test = tap.test('lj-788-limit-exponents-range')
-test:plan(2)
+test:plan(3)
-- Before the patch, the powers greater than (1 << 16) * 10
-- (655360) were parsed incorrectly. After the patch, powers
@@ -14,6 +14,7 @@ test:plan(2)
-- value bigger than `STRSCAN_MAXEXP` to check parsing correctness
-- for the first one, and `STRSCAN_ERROR` for the second case.
local PARSABLE_EXP_POWER = 1000000
+local STRSCAN_MAXEXP = 1048576
local TOO_LARGE_EXP_POWER = 1050000
local function form_exp_string(n)
@@ -21,9 +22,12 @@ local function form_exp_string(n)
end
test:is(tonumber(form_exp_string(PARSABLE_EXP_POWER)), 1,
- 'correct parsing of large exponent')
+ 'correct parsing of large exponent before the boundary')
+
+test:is(tonumber(form_exp_string(STRSCAN_MAXEXP)), nil,
+ 'boundary power of exponent is not parsed')
test:is(tonumber(form_exp_string(TOO_LARGE_EXP_POWER)), nil,
- 'too big exponent power is not parsed')
+ 'too big exponent power after the boundary is not parsed')
test:done(true)
===================================================================
>
> > +-- for the first one, and `STRSCAN_ERROR` for the second case.
> > +local PARSABLE_EXP_POWER = 1000000
> > +local TOO_LARGE_EXP_POWER = 1050000
> > +
> > +local function form_exp_string(n)
> > + return '0.' .. string.rep('0', n - 1) .. '1e' .. tostring(n)
> > +end
> > +
> > +test:is(tonumber(form_exp_string(PARSABLE_EXP_POWER)), 1,
> > + 'correct parsing of large exponent')
> > +
> > +test:is(tonumber(form_exp_string(TOO_LARGE_EXP_POWER)), nil,
> > + 'too big exponent power is not parsed')
> > +
> > +test:done(true)
--
Best regards,
Sergey Kaplun
More information about the Tarantool-patches
mailing list