From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Evgeniy Temirgaleev <e.temirgaleev@tarantool.org>,
Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 1/2] x86: Fix math.floor()/ceil() argument check.
Date: Mon, 23 Nov 2026 13:46:00 +0300 [thread overview]
Message-ID: <4a3e159dc353186f5ab439952190b83218e9cbf0.1795430601.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1795430601.git.skaplun@tarantool.org>
From: Mike Pall <mike>
Thanks to RaphaelIT7.
(cherry picked from commit acf8fcbd932a68d130fa3e3654e1b622e10fd6af)
The `math.floor()`, `math.ceil()` VM implementation uses the `.ffunc`
macro, which doesn't check the given arguments. If the top stack value
contains some garbage number value, it will be used as the function
result instead of raising an error.
This patch fixes the behaviour for non-GC64 mode by using the correct
`.ffunc_1` macro. The GC64 VM will be fixed in the next patch.
Sergey Kaplun:
* added the description and the test for the problem
Part of tarantool/tarantool#13442
---
src/vm_x86.dasc | 2 +-
.../lj-1532-math-floor-ceil-argcheck.test.lua | 36 +++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
index 19653fee..e875d073 100644
--- a/src/vm_x86.dasc
+++ b/src/vm_x86.dasc
@@ -2212,7 +2212,7 @@ static void build_subroutines(BuildCtx *ctx)
|.endif
|
|.macro math_round, func
- | .ffunc math_ .. func
+ | .ffunc_1 math_ .. func
|.if DUALNUM
| cmp dword [BASE+4], LJ_TISNUM; jne >1
| mov RB, dword [BASE]; jmp ->fff_resi
diff --git a/test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua b/test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua
new file mode 100644
index 00000000..b9def637
--- /dev/null
+++ b/test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua
@@ -0,0 +1,36 @@
+local tap = require('tap')
+
+-- Test file to demonstrate LuaJIT incorrect handling of no
+-- arguments for `math.ceil()`, `math.floor()` functions.
+-- See also: https://github.com/LuaJIT/LuaJIT/issues/1532.
+
+local test = tap.test('lj-1532-math-floor-ceil-argcheck')
+
+test:plan(2)
+
+-- A simple function to push a number value for `math.floor()`,
+-- `math.ceil()` to the Lua stack.
+local function stack()
+ return 1.2
+end
+
+local function call_wp(f)
+ stack() -- Push some value to the stack to mark the slot.
+ -- Use non-inlined variant for function name in the error
+ -- message.
+ local res = f()
+ return res
+end
+
+local function math_func_test(subtest, f)
+ subtest:plan(2)
+ local err, msg = pcall(call_wp, f)
+ subtest:is(err, false, 'correct status for empty ' .. subtest.name)
+ subtest:like(msg, "bad argument #1 to 'f' %(number expected, got no value%)",
+ 'correct error message for empty ' .. subtest.name)
+end
+
+test:test('math.ceil', math_func_test, math.ceil)
+test:test('math.floor', math_func_test, math.floor)
+
+test:done(true)
--
2.56.0
next prev parent reply other threads:[~2026-11-23 10:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 10:45 [Tarantool-patches] [PATCH luajit 0/2] " Sergey Kaplun via Tarantool-patches
2026-11-23 10:46 ` Sergey Kaplun via Tarantool-patches [this message]
2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 2/2] x64: " Sergey Kaplun 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=4a3e159dc353186f5ab439952190b83218e9cbf0.1795430601.git.skaplun@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=e.temirgaleev@tarantool.org \
--cc=sergeyb@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 1/2] x86: Fix math.floor()/ceil() argument check.' \
/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