<!DOCTYPE html>
<html data-lt-installed="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="padding-bottom: 1px;">
<p>Hi, Sergey,</p>
<p>thanks for the review. Fixes applied and force-pushed.</p>
<p>Sergey</p>
<div class="moz-cite-prefix">On 6/9/26 15:03, Sergey Kaplun via
Tarantool-patches wrote:<br>
</div>
<blockquote type="cite" cite="mid:aigBA_FxqFMura9f@root">
<pre wrap="" class="moz-quote-pre">Hi, Sergey!
Thanks for the patch!
LGTM, after fixing a few nits below.
On 09.06.26, Sergey Bronnikov wrote:
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">From: Mike Pall <mike>
Reported by Sergey Bronnikov.
(cherry picked from commit 8f421c81ec6aaae0bcd80e01f4353de200afbbc5)
The Undefined Behaviour Sanitizer [1] produce a warning because
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
Typo: s/produce/produces/</pre>
</blockquote>
<p>Fixed.</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:aigBA_FxqFMura9f@root">
<pre wrap="" class="moz-quote-pre">
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">the function `lua_createtable()` takes signed integer arguments,
but the `lj_tab_new_ah()` was not properly validating or converting
these signed values before using them in unsigned arithmetic.
The fix changes the signature of `lj_tab_new_ah()` to accept
uint32_t directly, and adjusts `lua_createtable()` to cast the
incoming signed int values to uint32_t before passing them.
[1]: <a class="moz-txt-link-freetext" href="https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html">https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html</a>
Sergey Bronnikov:
* added the description and the test for the problem
Part of tarantool/tarantool#12480
---
Branch: <a class="moz-txt-link-freetext" href="https://github.com/tarantool/luajit/tree/ligurio/lj-1458-ub-lj_tab_new">https://github.com/tarantool/luajit/tree/ligurio/lj-1458-ub-lj_tab_new</a>
Related issues:
- <a class="moz-txt-link-freetext" href="https://github.com/tarantool/tarantool/issues/12480">https://github.com/tarantool/tarantool/issues/12480</a>
- <a class="moz-txt-link-freetext" href="https://github.com/LuaJIT/LuaJIT/issues/1458">https://github.com/LuaJIT/LuaJIT/issues/1458</a>
src/lj_api.c | 2 +-
src/lj_tab.c | 4 +--
src/lj_tab.h | 2 +-
.../lj-1458-ub-table.new.test.lua | 30 +++++++++++++++++++
4 files changed, 34 insertions(+), 4 deletions(-)
create mode 100644 test/tarantool-tests/lj-1458-ub-table.new.test.lua
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
<snipped>
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">diff --git a/test/tarantool-tests/lj-1458-ub-table.new.test.lua b/test/tarantool-tests/lj-1458-ub-table.new.test.lua
new file mode 100644
index 00000000..d0cf6ff5
--- /dev/null
+++ b/test/tarantool-tests/lj-1458-ub-table.new.test.lua
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
Typo: s/table.new/table-new/</pre>
</blockquote>
Fixed.
<blockquote type="cite" cite="mid:aigBA_FxqFMura9f@root">
<pre wrap="" class="moz-quote-pre">
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">@@ -0,0 +1,30 @@
+local tap = require('tap')
+
+-- The test file to demonstrate UBSan warning for `table.new()`
+-- with a minimal and maximum array and hash parts values.
+-- See also: <a class="moz-txt-link-freetext" href="https://github.com/LuaJIT/LuaJIT/issues/1458">https://github.com/LuaJIT/LuaJIT/issues/1458</a>.
+local test = tap.test('lj-1458-ub-table-new')
+
+test:plan(8)
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
Lets use table_sizes * 2 here.
</pre>
</blockquote>
<p>Updated.</p>
<p><br>
</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:aigBA_FxqFMura9f@root">
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">+
+local table_new = require('table.new')
+
+local INT_MAX = 2 ^ 31 - 1
+local INT_MIN = -2 ^ 31
+
+local table_sizes = {
+ { 0, INT_MIN },
+ { 0, INT_MAX },
+ { INT_MIN, 0 },
+ { INT_MAX, 0 },
+}
+
+for _, case in ipairs(table_sizes) do
+ local apart, hpart = unpack(case)
+ local ok, err = pcall(table_new, apart, hpart)
+ local message = ('table.new(%d, %d)'):format(apart, hpart)
+ <a class="moz-txt-link-freetext" href="test:is(ok">test:is(ok</a>, false, message .. ' is failed')
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
Typo? s/failed/OK/</pre>
</blockquote>
<p><br>
</p>
<p>Right, fixed:</p>
<p>--- a/test/tarantool-tests/lj-1458-ub-table-new.test.lua<br>
+++ b/test/tarantool-tests/lj-1458-ub-table-new.test.lua<br>
@@ -23,7 +23,7 @@ for _, case in ipairs(table_sizes) do<br>
local apart, hpart = unpack(case)<br>
local ok, err = pcall(table_new, apart, hpart)<br>
local message = ('table.new(%d, %d)'):format(apart, hpart)<br>
- <a class="moz-txt-link-freetext" href="test:is(ok">test:is(ok</a>, false, message .. ' is failed')<br>
+ <a class="moz-txt-link-freetext" href="test:is(ok">test:is(ok</a>, false, message .. ' is ok')<br>
<a class="moz-txt-link-freetext" href="test:ok(err:match('table">test:ok(err:match('table</a> overflow'), message .. ' correct error
message')<br>
end<br>
<br>
</p>
<blockquote type="cite" cite="mid:aigBA_FxqFMura9f@root">
<pre wrap="" class="moz-quote-pre">
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">+ <a class="moz-txt-link-freetext" href="test:ok(err:match('table">test:ok(err:match('table</a> overflow'), message .. ' correct error message')
+end
+
+test:done(true)
--
2.43.0
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
</pre>
</blockquote>
</body>
<lt-container></lt-container>
</html>