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 DAFEB6F15B; Tue, 23 Aug 2022 17:30:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DAFEB6F15B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1661265022; bh=GhEZ0/txYac3hn1QiX7uFq++dCnUjZyK5eZeTYrRdrE=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=a9QpwdWY4WhVpQdKQ16l0h2/wGbK+Ga1uJMoT1c4oxna8PxeyYX2WrrJBgfTlbIqk QEV+Zrt5MSsfUTFN/NYwOnJAEE4AzOMXQFhNLHByEChQvMy0ryyp6v1rB6jiW/Az7X lhHyIcR3ZuXbmTbpfw6DuQi6qK5jezcpsdb+BBwo= 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 354296F15B for ; Tue, 23 Aug 2022 17:30:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 354296F15B Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1oQUv2-0007xT-7S; Tue, 23 Aug 2022 17:30:16 +0300 To: Sergey Ostanevich , Maxim Kokryashkin Date: Tue, 23 Aug 2022 17:27:41 +0300 Message-Id: <20220823142741.2729-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD92C1BB4A9562080D0241FCA21F9D358A9F086B9F0FA6F79DF182A05F5380850404C228DA9ACA6FE2750B57627D4C09F108771725128ED010BCAD5CCC80F0FB57EF0F10434B89A70F4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74AA616721CED6291EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A6A20D80F0832BC78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D805B2AE68C4CF0915251250ED6C79FA1C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B642416645EBD45DC2089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C41E93BD56E7067354307CAA32FF218580205367B2BCC23E5BA5F4B7DCB1B017D3E7E65F06B2D3BF1CAD91A466A1DEF99B6ED91DBE5ABE359A3485EE9140A7D39DC234C8B12C006B741A734B94837AEB0ADDE094C8E3E8326B5BA5F62F985B710FB1881A6453793CE9C32612AADDFBE061E7CF831D07CEC04EA71A35648BE338CE9510FB958DCE06DB58C12E6D310A6D5333F7A9E5587C79A693EDB24507CE13387DFF0A840B692CF8 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D9DC20663B80603F0641C220475E91A227C8EDB660EFD2245BEB6BA6F0F2520A1CD1325991FB36A81D7E09C32AA3244C172341C66B18450B0BAAD0C55F8CF7BEFE8DA44ABE2443F7927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojzEOgLjt8B1rZPQ3sNWVHjQ== X-DA7885C5: E8C6E5D73DB792FEC89783D3C9695EC943A9ED4630FB14C22297B5785661668B262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F7393CC2E0F076E87284EA4C0A2C1AEE21944297E11D87ED840820FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] FFI: Always fall back to metamethods for cdata length/concat. 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 Thanks to Egor Skriptunoff. (cherry picked from commit cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0) When user tries to concatenate 2 cdata objects without declared metamethod, the assertion is raised in `carith_int64()`, due to concatenation operation is not specified and default (assert) branch is taken. This patch forcifies usage of metamethod for concatenation on cdata objects. Also, as far as the behaviour for length operation is the same, the `lj_carith_len()` routine is removed, its call is replaced with `ffi_arith()`. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#7230 --- Issue: https://github.com/tarantool/tarantool/issues/7230 Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-cdata-ll-concat-full-ci PR: https://github.com/tarantool/tarantool/pull/7598 ML: https://www.freelists.org/post/luajit/cdata-concatenation src/lj_carith.c | 3 +-- src/lj_crecord.c | 6 ++++-- test/tarantool-tests/fix-cdata-concat.test.lua | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/tarantool-tests/fix-cdata-concat.test.lua diff --git a/src/lj_carith.c b/src/lj_carith.c index 218abd26..04c18054 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c @@ -265,7 +265,7 @@ int lj_carith_op(lua_State *L, MMS mm) { CTState *cts = ctype_cts(L); CDArith ca; - if (carith_checkarg(L, cts, &ca)) { + if (carith_checkarg(L, cts, &ca) && mm != MM_len && mm != MM_concat) { if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) { copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace recorder. */ return 1; @@ -347,7 +347,6 @@ uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id) } } - /* -- 64 bit integer arithmetic helpers ----------------------------------- */ #if LJ_32 && LJ_HASJIT diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 0d7b71f0..3d562d9a 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -1546,8 +1546,10 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) } { TRef tr; - if (!(tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) && - !(tr = crec_arith_ptr(J, sp, s, (MMS)rd->data)) && + MMS mm = (MMS)rd->data; + if ((mm == MM_len || mm == MM_concat || + (!(tr = crec_arith_int64(J, sp, s, mm)) && + !(tr = crec_arith_ptr(J, sp, s, mm)))) && !(tr = crec_arith_meta(J, sp, s, cts, rd))) return; J->base[0] = tr; diff --git a/test/tarantool-tests/fix-cdata-concat.test.lua b/test/tarantool-tests/fix-cdata-concat.test.lua new file mode 100644 index 00000000..aaeb36fa --- /dev/null +++ b/test/tarantool-tests/fix-cdata-concat.test.lua @@ -0,0 +1,15 @@ +local tap = require('tap') + +-- Test file to demonstrate incorrect behaviour of cdata +-- concatenation in LuaJIT. +-- See also +-- https://www.freelists.org/post/luajit/cdata-concatenation. +local test = tap.test('cdata-concat') +test:plan(1) + +local r, e = pcall(function() + return 1LL .. 2LL +end) +test:ok(not r and e:match('attempt to concatenate'), 'cdata concatenation') + +os.exit(test:check() and 0 or 1) -- 2.34.1