From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id DC2955B3381; Thu, 24 Aug 2023 13:07:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DC2955B3381 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1692871641; bh=S+DmGqqX2WsDRsyI449UYY9SLCz5i90tNMYsuuo0MU0=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=B0o+ZDpvNgU6UNlCpsAZ3ZNXGb7386Ky3nNZkBh8/svcdiS08eiYLr1pgNhAkVqEA +AHWmpKeMdVI/eRcQczvEiubtKYfvIGwTo8VYzhrSQX6tBIG6ju8/6IPje60izH4aY Ka7qYpNz2LmIJBT/mDYoL4YhbsaPLZUrLfu8yQ0c= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 87A8B5B3381 for ; Thu, 24 Aug 2023 13:07:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 87A8B5B3381 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1qZ7FG-0007Z7-F6; Thu, 24 Aug 2023 13:07:19 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Thu, 24 Aug 2023 13:02:33 +0300 Message-ID: <20230824100233.25009-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD93C8852532D76B9E3B40810D8949158306E0746822E25C650182A05F5380850405B5F46ABBA2E965CB1BA7B4265889AA51305A41C48B4003BC1C0D74D32D1DB60 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE701173C01F417A2A6EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373318DFCEF5C6D9308638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B0EAC9E1BD3195BB66F569202B45DEC5117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF80095D1ED7F4578A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FBDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269176DF2183F8FC7C088D2E8BEBF93D4B068655334FD4449CB33AC447995A7AD1857739F23D657EF2BD5E8D9A59859A8B6821DB69C87B6DA73089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5C0C1F2AB1202B2ACCA51BDBF643C950085DB178DECCC6924F87CCE6106E1FC07E67D4AC08A07B9B064E7220B7C5505929C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF77DD89D51EBB7742D3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFFF35DE894D9B606410D995EDECBAC8289446254F49CD5750BED5A553B90D8F262DF5FAC740BFE7CD65277D9847CC050A1EE4BC59DF765B8ED8A5804C8D604B6DA74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbN4zljfpmjH8yZpJOsodOw== X-DA7885C5: 01F5EF7D34D2598CB94A40E258193423DF291258515389A3B63E30E92746B492262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986BF8EDBFF61F5FCB625DDB69563808274B0FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] Fix binary number literal parsing. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Reported by Egor Skriptunoff. (cherry-picked from commit 377a8488b62a9f1b589bb68875dd1288aa70e76e) Binary number with fractional part is invalid. Parsing of such binary numbers returns `STRSCAN_ERROR` for any numbers with non-zero fractional part, because it gives non-zero power of the exponent (`ex2`) in `strscan_bin()`. But binary numbers with a zero fractional part considered as valid numbers. To avoid such inconsistency the check, that the given base doesn't equal 2, is added, when parsing decimal point part of the literal. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#8825 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/fix-binary-number-parsing Issue: https://github.com/tarantool/tarantool/issues/8825 ML: https://www.freelists.org/post/luajit/Fractional-binary-number-literals Tarantool PR: https://github.com/tarantool/tarantool/pull/9028 Tarantool's CI is red, because static build on aarch64 can't fetch the LuaJIT's submodule commit somehow. Looks unrelated to the commit:). src/lj_strscan.c | 1 + .../fix-binary-number-parsing.test.lua | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/tarantool-tests/fix-binary-number-parsing.test.lua diff --git a/src/lj_strscan.c b/src/lj_strscan.c index 11d341ee..a2d92714 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c @@ -444,6 +444,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, /* Handle decimal point. */ if (dp) { + if (base == 2) return STRSCAN_ERROR; fmt = STRSCAN_NUM; if (dig) { ex = (int32_t)(dp-(p-1)); dp = p-1; diff --git a/test/tarantool-tests/fix-binary-number-parsing.test.lua b/test/tarantool-tests/fix-binary-number-parsing.test.lua new file mode 100644 index 00000000..df82bd0b --- /dev/null +++ b/test/tarantool-tests/fix-binary-number-parsing.test.lua @@ -0,0 +1,17 @@ +local tap = require('tap') + +-- Test file to demonstrate incorrect behaviour of binary number +-- parsing with fractional dot. +-- See also: +-- https://www.freelists.org/post/luajit/Fractional-binary-number-literals +local test = tap.test('fix-binary-number-parsing') +test:plan(2) + +-- Test that incorrect literal with non-0 fractional part still +-- can't be converted to number. +test:is(tonumber('0b.1'), nil, '0b.1 is not converted') +-- Test that incorrect literal with 0 fractional part can't be +-- converted to number. +test:is(tonumber('0b.0'), nil, '0b.0 is not converted') + +test:done(true) -- 2.41.0