From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Bronnikov <estetus@gmail.com> Cc: max.kokryashkin@gmail.com, tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit] LJ_GC64: Fix lua_concat(). Date: Thu, 23 Nov 2023 06:31:52 +0000 [thread overview] Message-ID: <ZV7x2LijXCKihjHw@tarantool.org> (raw) In-Reply-To: <26636e3dcb8ade3bdc23d9544f9a7e2ffe4322b2.1695711374.git.sergeyb@tarantool.org> Sergey, I've checked the patchset into all long-term branches in tarantool/luajit and bumped a new version in master, release/2.11 and release/2.10. On 26.09.23, Sergey Bronnikov via Tarantool-patches wrote: > From: Sergey Bronnikov <sergeyb@tarantool.org> > > Reported by Mathias Westerdahl. > > (cherry picked from commit 633f265f67f322cbe2c5fd11d3e46d968ac220f7) > > Lua 5.1 Reference Manual [1] defines a function `lua_concat`, that: > > > void lua_concat (lua_State *L, int n); > > > > Concatenates the n values at the top of the stack, pops them, and leaves > > the result at the top. > > Without the patch `lua_concat()` behaved incorrectly with userdata with > defined `__concat` metamethod. The problem is GC64-specific. > > Assuming we have three literals and a userdata with defined "__concat" > metamethod on top of the Lua stack: > > 1 [string] > 2 [string] > 3 [string] > 4 [string] > 5 [userdata] <--- top > > On attempt to concatenate *two* items on top Lua stack, `lua_concat()` > concatenates *four* items and leaves result at the top: > > 1 [string] > 2 [string][string][string][userdata] <--- top > > The problem is in incorrect calculation of `n` counter in a loop in > implementation of function `lua_concat`. Without a fix `n` is equal to 3 > at the end of the first iteration and therefore it goes to the next > iteration of concatenation. In a fixed implementation of `lua_concat()` > `n` is equal to 1 at the end of the first loop iteration, decremented in > a loop postcondition and breaks a loop. > > The patch fixes incorrect behaviour. > > 1. https://www.lua.org/manual/5.1/manual.html > > Sergey Bronnikov: > * added the description and the test for the problem > > Part of tarantool/tarantool#8825 > --- > PR: https://github.com/tarantool/tarantool/pull/9176 > Branch: https://github.com/tarantool/luajit/commits/ligurio/lj-881-fix-concat > Issues: > - https://github.com/LuaJIT/LuaJIT/issues/881 > - https://github.com/tarantool/tarantool/issues/8825 > > src/lj_api.c | 2 +- > .../lj-881-fix-lua-concat.test.c | 116 ++++++++++++++++++ > 2 files changed, 117 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-c-tests/lj-881-fix-lua-concat.test.c > <snipped> > -- > 2.34.1 > -- Best regards, IM
prev parent reply other threads:[~2023-11-23 6:38 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <cover.1698775628.git.sergeyb@tarantool.org> 2023-09-26 6:56 ` Sergey Bronnikov via Tarantool-patches 2023-09-29 8:24 ` Maxim Kokryashkin via Tarantool-patches 2023-10-03 15:35 ` Sergey Bronnikov via Tarantool-patches 2023-10-04 10:48 ` Maxim Kokryashkin via Tarantool-patches 2023-10-06 13:51 ` Sergey Bronnikov via Tarantool-patches 2023-10-31 18:11 ` [Tarantool-patches] [PATCH luajit 1/2] test: introduce asserts assert_str{_not}_equal Sergey Bronnikov via Tarantool-patches 2023-11-01 7:40 ` Sergey Kaplun via Tarantool-patches 2023-11-01 8:28 ` Igor Munkin via Tarantool-patches 2023-11-10 11:41 ` Sergey Bronnikov via Tarantool-patches 2023-11-14 8:55 ` Sergey Kaplun via Tarantool-patches 2023-11-15 9:32 ` Sergey Bronnikov via Tarantool-patches 2023-11-16 8:02 ` Sergey Kaplun via Tarantool-patches 2023-11-18 16:40 ` Sergey Bronnikov via Tarantool-patches 2023-11-20 9:28 ` Sergey Kaplun via Tarantool-patches 2023-11-20 13:19 ` Igor Munkin via Tarantool-patches 2023-11-10 11:40 ` Sergey Bronnikov via Tarantool-patches 2023-11-23 6:31 ` Igor Munkin via Tarantool-patches [this message]
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=ZV7x2LijXCKihjHw@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=estetus@gmail.com \ --cc=imun@tarantool.org \ --cc=max.kokryashkin@gmail.com \ --subject='Re: [Tarantool-patches] [PATCH luajit] LJ_GC64: Fix lua_concat().' \ /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