From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit] Limit exponent range in number parsing.
Date: Thu, 25 Jan 2024 19:31:09 +0300 [thread overview]
Message-ID: <6c5cfdc0-410c-4bf1-bc1d-f895d4ef3519@tarantool.org> (raw)
In-Reply-To: <ZbIyqLE4x39IJNuS@root>
Thanks! LGTM now
On 1/25/24 13:06, Sergey Kaplun wrote:
> 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)
next prev parent reply other threads:[~2024-01-25 16:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-21 8:52 Sergey Kaplun via Tarantool-patches
2023-11-21 23:14 ` Maxim Kokryashkin via Tarantool-patches
2024-01-23 21:14 ` Sergey Kaplun via Tarantool-patches
2024-01-25 7:47 ` Sergey Bronnikov via Tarantool-patches
2024-01-25 10:06 ` Sergey Kaplun via Tarantool-patches
2024-01-25 16:31 ` Sergey Bronnikov via Tarantool-patches [this message]
2024-02-15 13:50 ` Igor Munkin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c5cfdc0-410c-4bf1-bc1d-f895d4ef3519@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=sergeyb@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit] Limit exponent range in number parsing.' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox