[Tarantool-patches] [PATCH luajit] Limit exponent range in number parsing.
Sergey Bronnikov
sergeyb at tarantool.org
Thu Jan 25 10:47:56 MSK 2024
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
> +-- 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)
More information about the Tarantool-patches
mailing list