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 45F8719F8E72; Mon, 30 Mar 2026 15:54:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 45F8719F8E72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1774875268; bh=6WskNJpLQaXEtvZopEzvzVtjtvjm/TMdHFdM0QOmp3A=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ySuTyCGru51hi1q3D+XmrdqMbDXclOz/vEJrq8ftm1BVCtTLUZfIkskVCgicqkdlh 9aD4tr1sLEbKVfa+KDtUpr6zFSRPMH3UfEeS+Ks/kyF2QObRK37KkK3d4/BMN0JfjZ KoK4IJ0sMlV1LsIXFBm9a493TGilrPilr0FtVGrY= Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 756E91B5698F for ; Mon, 30 Mar 2026 15:54:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 756E91B5698F Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5a2a70bb69eso4632871e87.2 for ; Mon, 30 Mar 2026 05:54:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774875266; x=1775480066; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0xCgnLn6kwCmUpn7YptpAZ5g15IIVJ16u5dU8BymGZo=; b=MbGG3gcq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EmgOcjFi5k= X-Received: by 2002:a05:6512:3d05:b0:5a2:7cd6:d5eb with SMTP id 2adb3069b0e04-5a2ab92614cmr5401010e87.27.1774875265470; Mon, 30 Mar 2026 05:54:25 -0700 (PDT) Received: from localhost ([2a06:a780:1000:2::df58:9e78]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a2b1403cb6sm1641056e87.27.2026.03.30.05.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 05:54:24 -0700 (PDT) X-Google-Original-From: Sergey Bronnikov Date: Mon, 30 Mar 2026 15:54:23 +0300 To: Sergey Kaplun Cc: Sergey Bronnikov , tarantool-patches@dev.tarantool.org Message-ID: References: <7183dd75158a7191fc2b08ae43e17e4f3d1afcf2.1774870754.git.sergeyb@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: X-Url: https://bronevichok.ru/ Subject: Re: [Tarantool-patches] [PATCH luajit] Prevent false positive sanitizer warning in unpack(). 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! thanks for the review! Fixes were applied and branch was force-pushed. Sergey On 15:30 Mon 30 Mar , Sergey Kaplun via Tarantool-patches wrote: >Hi, Sergey! >Thanks for the patch! >LGTM, after fixing my minor comments below. > >On 30.03.26, Sergey Bronnikov wrote: >> From: Mike Pall >> >> Reported by Sergey Bronnikov. >> >> (cherry picked from commit f322ecb51e3cea06683cc201e8ce224ec42fdab8) >> >> The UndefinedBehaviour sanitizer produce a runtime warning when > >Typo: s/produce/produces/ Fixed, thanks! > >> INT_MAX is passed to `unpack()` as index `j`. This happens because > >Typo: s/j/i/ Right, fixed! > >> `i` in lj_cf_unpack() was incremented before the checking loop >> invariant and this could to a signed integer overflo. The patch > >Typo: s/could to/leads to/ >Typo: s/overflo/overflow/ Fixed. > >> fixes the issue by moving a loop invariant to a loop body. > >Minor: It is rather "by moving index incrementation in the separate >statement from the loop invariant check". > Updated. >> >> Sergey Bronnikov: >> * added the description and the test for the problem >> >> Part of tarantool/tarantool#12134 >> --- >> >> Branch: https://github.com/tarantool/luajit/tree/ligurio/lj-1450-unpack-ub >> Related issues: >> * https://github.com/LuaJIT/LuaJIT/issues/1450 >> * https://github.com/tarantool/tarantool/issues/12134 >> >> src/lib_base.c | 4 ++- >> .../lj-1450-unpack-huge-indices.test.lua | 28 +++++++++++++++++++ >> 2 files changed, 31 insertions(+), 1 deletion(-) >> create mode 100644 test/tarantool-tests/lj-1450-unpack-huge-indices.test.lua >> >> diff --git a/src/lib_base.c b/src/lib_base.c >> index a5b907de..714dc5bf 100644 >> --- a/src/lib_base.c >> +++ b/src/lib_base.c > > > >> diff --git a/test/tarantool-tests/lj-1450-unpack-huge-indices.test.lua b/test/tarantool-tests/lj-1450-unpack-huge-indices.test.lua >> new file mode 100644 >> index 00000000..1a09e273 >> --- /dev/null >> +++ b/test/tarantool-tests/lj-1450-unpack-huge-indices.test.lua >> @@ -0,0 +1,28 @@ >> +local tap = require('tap') >> + >> +-- The test file to demonstrate UBSan warning for `unpack()` with >> +-- a huge indices value. >> +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1450. >> +local test = tap.test('lj-1450-unpack-huge-indices') >> + >> +test:plan(4) >> + >> +local INT_MAX = 2 ^ 31 - 1 >> + >> +-- The first test check the UBSan runtime error. The assertions > >Typo: s/check/checks/ Fixed. > >> +-- were added just to be sure we don't change the behaviour. >> +-- The second test additionally check a correct behaviour for > >Typo: s/check/checks/ Fixed. local INT_MAX = 2 ^ 31 - 1 --- The first test check the UBSan runtime error. The assertions +-- The first test checks the UBSan runtime error. The assertions -- were added just to be sure we don't change the behaviour. --- The second test additionally check a correct behaviour for +-- The second test additionally checks a correct behaviour for -- a value. local tbl = { [INT_MAX] = INT_MAX, [INT_MAX - 1] = INT_MAX - 1, } > >> +-- a value. >> +local tbl = { >> + [INT_MAX] = INT_MAX, >> + [INT_MAX - 1] = INT_MAX - 1, > >I suggest creating for this value the `INT_MAX_M1` variable. >Feel free to ignore. IMHO this variable name is less clear than using INT_MAX - 1. Left without changes. > >> +} >> +local status, res = pcall(unpack, tbl, INT_MAX, INT_MAX) > >`pcall()`-s look excessive here since we always expect only 1 element to >be unpacked, so we obviously have enough space for it. Let's drop them. > Updated: local tbl = { [INT_MAX] = INT_MAX, [INT_MAX - 1] = INT_MAX - 1, } -local status, res = pcall(unpack, tbl, INT_MAX, INT_MAX) -test:ok(status, 'unpack with INT_MAX: correct status') +local res = unpack(tbl, INT_MAX, INT_MAX) test:is(res, INT_MAX, 'unpack with INT_MAX: correct result') -status, res = pcall(unpack, tbl, INT_MAX - 1, INT_MAX - 1) -test:ok(status, 'unpack with INT_MAX - 1: correct status') +res = unpack(tbl, INT_MAX - 1, INT_MAX - 1) test:is(res, INT_MAX - 1, 'unpack with INT_MAX - 1: correct result') test:done(true) >> +test:ok(status, 'unpack with INT_MAX: correct status') >> +test:is(res, INT_MAX, 'unpack with INT_MAX: correct result') >> + >> +status, res = pcall(unpack, tbl, INT_MAX - 1, INT_MAX - 1) >> +test:ok(status, 'unpack with INT_MAX - 1: correct status') >> +test:is(res, INT_MAX - 1, 'unpack with INT_MAX - 1: correct result') >> + >> +test:done(true) >> -- >> 2.43.0 >> > >-- >Best regards, >Sergey Kaplun > -- sergeyb@