Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH luajit 0/2] Fix math.floor()/ceil() argument check.
@ 2026-11-23 10:45 Sergey Kaplun via Tarantool-patches
  2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 1/2] x86: " Sergey Kaplun via Tarantool-patches
  2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 2/2] x64: " Sergey Kaplun via Tarantool-patches
  0 siblings, 2 replies; 3+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2026-11-23 10:45 UTC (permalink / raw)
  To: Evgeniy Temirgaleev, Sergey Bronnikov; +Cc: tarantool-patches

Patches fixes x86 and x64 VMs (correspondingly) arguemnt check for the
aforementioned functions.

Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1532-math-floor-ceil-argcheck
Related issues:
* https://github.com/LuaJIT/LuaJIT/issues/1532
* https://github.com/tarantool/tarantool/issues/13442

Side note: The CI on macOS x86_64 is red due to runner problems.

Mike Pall (2):
  x86: Fix math.floor()/ceil() argument check.
  x64: Fix math.floor()/ceil() argument check.

 src/vm_x64.dasc                               |  2 +-
 src/vm_x86.dasc                               |  2 +-
 .../lj-1532-math-floor-ceil-argcheck.test.lua | 36 +++++++++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua

-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Tarantool-patches] [PATCH luajit 1/2] x86: Fix math.floor()/ceil() argument check.
  2026-11-23 10:45 [Tarantool-patches] [PATCH luajit 0/2] Fix math.floor()/ceil() argument check Sergey Kaplun via Tarantool-patches
@ 2026-11-23 10:46 ` Sergey Kaplun via Tarantool-patches
  2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 2/2] x64: " Sergey Kaplun via Tarantool-patches
  1 sibling, 0 replies; 3+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2026-11-23 10:46 UTC (permalink / raw)
  To: Evgeniy Temirgaleev, Sergey Bronnikov; +Cc: tarantool-patches

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Tarantool-patches] [PATCH luajit 2/2] x64: Fix math.floor()/ceil() argument check.
  2026-11-23 10:45 [Tarantool-patches] [PATCH luajit 0/2] Fix math.floor()/ceil() argument check Sergey Kaplun via Tarantool-patches
  2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 1/2] x86: " Sergey Kaplun via Tarantool-patches
@ 2026-11-23 10:46 ` Sergey Kaplun via Tarantool-patches
  1 sibling, 0 replies; 3+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2026-11-23 10:46 UTC (permalink / raw)
  To: Evgeniy Temirgaleev, Sergey Bronnikov; +Cc: tarantool-patches

From: Mike Pall <mike>

Thanks to RaphaelIT7.

(cherry picked from commit 849bbbe763e38080ae7ec6bd9b2be34156ec6b80)

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 GC64 mode by using the correct
`.ffunc_1` macro. The test is the same as for the non-GC64 mode.

Sergey Kaplun:
* added the description for the problem

Part of tarantool/tarantool#13442
---
 src/vm_x64.dasc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc
index 2eb4d752..e17f84e9 100644
--- a/src/vm_x64.dasc
+++ b/src/vm_x64.dasc
@@ -1798,7 +1798,7 @@ static void build_subroutines(BuildCtx *ctx)
   |  jmp ->vm_return
   |
   |.macro math_round, func
-  |  .ffunc math_ .. func
+  |  .ffunc_1 math_ .. func
   |.if DUALNUM
   |  mov RB, [BASE]
   |  checknumx RB, ->fff_resRB, je
-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-23 10:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 10:45 [Tarantool-patches] [PATCH luajit 0/2] Fix math.floor()/ceil() argument check Sergey Kaplun via Tarantool-patches
2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 1/2] x86: " Sergey Kaplun via Tarantool-patches
2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 2/2] x64: " Sergey Kaplun via Tarantool-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox