* [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
@ 2026-06-05 15:18 Sergey Bronnikov via Tarantool-patches
2026-06-06 7:14 ` Sergey Kaplun via Tarantool-patches
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2026-06-05 15:18 UTC (permalink / raw)
To: tarantool-patches, Sergey Kaplun, e.temirgaleev
From: Mike Pall <mike>
Reported by Sergey Bronnikov.
(cherry picked from commit 86d414f5cae062b06998ec66b0696a47d4f6a0f0)
The function `lj_cf_os_time()` calculates `tm_mon` and `tm_year`
values using `get_field()` and when the helper function returns
a negative value the resulted values may be negative as well. This
is an undefined behaviour (signed integer overflow). The patch fixes
that by adding a cast for the resulted value to returned by
`get_field()`.
Sergey Bronnikov:
* added the description and the test for the problem
Part of tarantool/tarantool#12480
---
Branch: https://github.com/tarantool/luajit/tree/ligurio/lj-1454-ub-os-time
Related issues:
* https://github.com/tarantool/tarantool/issues/12480
* https://github.com/LuaJIT/LuaJIT/issues/1454
src/lib_os.c | 4 ++--
test/tarantool-tests/lj-1454-os-time.test.lua | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
create mode 100644 test/tarantool-tests/lj-1454-os-time.test.lua
diff --git a/src/lib_os.c b/src/lib_os.c
index ffbc3fdc..0feb0d47 100644
--- a/src/lib_os.c
+++ b/src/lib_os.c
@@ -239,8 +239,8 @@ LJLIB_CF(os_time)
ts.tm_min = getfield(L, "min", 0);
ts.tm_hour = getfield(L, "hour", 12);
ts.tm_mday = getfield(L, "day", -1);
- ts.tm_mon = getfield(L, "month", -1) - 1;
- ts.tm_year = getfield(L, "year", -1) - 1900;
+ ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u);
+ ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u);
ts.tm_isdst = getboolfield(L, "isdst");
t = mktime(&ts);
}
diff --git a/test/tarantool-tests/lj-1454-os-time.test.lua b/test/tarantool-tests/lj-1454-os-time.test.lua
new file mode 100644
index 00000000..2a48750c
--- /dev/null
+++ b/test/tarantool-tests/lj-1454-os-time.test.lua
@@ -0,0 +1,19 @@
+local tap = require('tap')
+
+-- The test file to demonstrate UBSan warning for `os.time()` with
+-- a huge indices value for month and/or year.
+-- See also: https://github.com/LuaJIT/LuaJIT/issues/1454.
+local test = tap.test('lj-1454-os-time')
+
+test:plan(1)
+
+local INT_MIN = -2 ^ 31
+
+local cur_time = os.time({
+ day = 1,
+ month = INT_MIN,
+ year = INT_MIN,
+})
+test:is(cur_time, nil, 'os.time() with INT_MIN')
+
+test:done(true)
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
2026-06-05 15:18 [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time() Sergey Bronnikov via Tarantool-patches
@ 2026-06-06 7:14 ` Sergey Kaplun via Tarantool-patches
2026-06-08 10:59 ` Sergey Bronnikov via Tarantool-patches
2026-06-11 11:44 ` Evgeniy Temirgaleev via Tarantool-patches
2026-06-11 11:55 ` Evgeniy Temirgaleev via Tarantool-patches
2 siblings, 1 reply; 8+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2026-06-06 7:14 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the patch!
LGTM, with minor ignorable comments below.
On 05.06.26, Sergey Bronnikov wrote:
> From: Mike Pall <mike>
>
> Reported by Sergey Bronnikov.
>
> (cherry picked from commit 86d414f5cae062b06998ec66b0696a47d4f6a0f0)
>
> The function `lj_cf_os_time()` calculates `tm_mon` and `tm_year`
> values using `get_field()` and when the helper function returns
> a negative value the resulted values may be negative as well. This
> is an undefined behaviour (signed integer overflow). The patch fixes
> that by adding a cast for the resulted value to returned by
Typo: s/to returned/to be returned/
> `get_field()`.
I am suggesting rephrasing this paragraph a bit to make it more clear:
| The function `lj_cf_os_time()` calculates the `tm_mon` and `tm_year`
| values using `get_field()`. If this helper function returns a negative
| result, subtraction may lead to undefined behavior due to signed integer
| overflow. The patch fixes the issue by adding a cast to the value
| returned by `get_field()`.
Feel free to ignore.
>
> Sergey Bronnikov:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#12480
> ---
>
> Branch: https://github.com/tarantool/luajit/tree/ligurio/lj-1454-ub-os-time
>
> Related issues:
>
> * https://github.com/tarantool/tarantool/issues/12480
> * https://github.com/LuaJIT/LuaJIT/issues/1454
>
> src/lib_os.c | 4 ++--
> test/tarantool-tests/lj-1454-os-time.test.lua | 19 +++++++++++++++++++
> 2 files changed, 21 insertions(+), 2 deletions(-)
> create mode 100644 test/tarantool-tests/lj-1454-os-time.test.lua
>
> diff --git a/src/lib_os.c b/src/lib_os.c
> index ffbc3fdc..0feb0d47 100644
> --- a/src/lib_os.c
> +++ b/src/lib_os.c
<snipped>
> diff --git a/test/tarantool-tests/lj-1454-os-time.test.lua b/test/tarantool-tests/lj-1454-os-time.test.lua
> new file mode 100644
> index 00000000..2a48750c
> --- /dev/null
> +++ b/test/tarantool-tests/lj-1454-os-time.test.lua
I prefer the <lj-1454-ub-os-time.test.lua> name (as you named the
branch). Feel free to ignore.
> @@ -0,0 +1,19 @@
> +local tap = require('tap')
> +
> +-- The test file to demonstrate UBSan warning for `os.time()` with
> +-- a huge indices value for month and/or year.
s/a huge indices value/huge negative index values/
> +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1454.
> +local test = tap.test('lj-1454-os-time')
I prefer the lj-1454-ub-os-time name (as you named the branch). Feel
free to ignore.
> +
> +test:plan(1)
> +
> +local INT_MIN = -2 ^ 31
> +
> +local cur_time = os.time({
> + day = 1,
> + month = INT_MIN,
> + year = INT_MIN,
> +})
> +test:is(cur_time, nil, 'os.time() with INT_MIN')
> +
> +test:done(true)
> --
> 2.43.0
>
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
2026-06-06 7:14 ` Sergey Kaplun via Tarantool-patches
@ 2026-06-08 10:59 ` Sergey Bronnikov via Tarantool-patches
2026-06-08 11:03 ` Sergey Kaplun via Tarantool-patches
0 siblings, 1 reply; 8+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2026-06-08 10:59 UTC (permalink / raw)
To: Sergey Kaplun, Sergey Bronnikov; +Cc: tarantool-patches
[-- Attachment #1: Type: text/plain, Size: 3725 bytes --]
Hi, Sergey,
thanks for the review! See my comments below.
Sergey
On 6/6/26 10:14, Sergey Kaplun via Tarantool-patches wrote:
> Hi, Sergey!
> Thanks for the patch!
> LGTM, with minor ignorable comments below.
>
> On 05.06.26, Sergey Bronnikov wrote:
>> From: Mike Pall <mike>
>>
>> Reported by Sergey Bronnikov.
>>
>> (cherry picked from commit 86d414f5cae062b06998ec66b0696a47d4f6a0f0)
>>
>> The function `lj_cf_os_time()` calculates `tm_mon` and `tm_year`
>> values using `get_field()` and when the helper function returns
>> a negative value the resulted values may be negative as well. This
>> is an undefined behaviour (signed integer overflow). The patch fixes
>> that by adding a cast for the resulted value to returned by
> Typo: s/to returned/to be returned/
Fixed.
>
>> `get_field()`.
> I am suggesting rephrasing this paragraph a bit to make it more clear:
>
> | The function `lj_cf_os_time()` calculates the `tm_mon` and `tm_year`
> | values using `get_field()`. If this helper function returns a negative
> | result, subtraction may lead to undefined behavior due to signed integer
> | overflow. The patch fixes the issue by adding a cast to the value
> | returned by `get_field()`.
>
> Feel free to ignore.
Updated.
>
>> Sergey Bronnikov:
>> * added the description and the test for the problem
>>
>> Part of tarantool/tarantool#12480
>> ---
>>
>> Branch:https://github.com/tarantool/luajit/tree/ligurio/lj-1454-ub-os-time
>>
>> Related issues:
>>
>> *https://github.com/tarantool/tarantool/issues/12480
>> *https://github.com/LuaJIT/LuaJIT/issues/1454
>>
>> src/lib_os.c | 4 ++--
>> test/tarantool-tests/lj-1454-os-time.test.lua | 19 +++++++++++++++++++
>> 2 files changed, 21 insertions(+), 2 deletions(-)
>> create mode 100644 test/tarantool-tests/lj-1454-os-time.test.lua
>>
>> diff --git a/src/lib_os.c b/src/lib_os.c
>> index ffbc3fdc..0feb0d47 100644
>> --- a/src/lib_os.c
>> +++ b/src/lib_os.c
> <snipped>
>
>> diff --git a/test/tarantool-tests/lj-1454-os-time.test.lua b/test/tarantool-tests/lj-1454-os-time.test.lua
>> new file mode 100644
>> index 00000000..2a48750c
>> --- /dev/null
>> +++ b/test/tarantool-tests/lj-1454-os-time.test.lua
> I prefer the <lj-1454-ub-os-time.test.lua> name (as you named the
> branch). Feel free to ignore.
Updated:
$ git show --name-only
<snipped>
src/lib_os.c
test/tarantool-tests/lj-1454-ub-os-time.test.lua
>> @@ -0,0 +1,19 @@
>> +local tap = require('tap')
>> +
>> +-- The test file to demonstrate UBSan warning for `os.time()` with
>> +-- a huge indices value for month and/or year.
> s/a huge indices value/huge negative index values/
Updated:
--- a/test/tarantool-tests/lj-1454-ub-os-time.test.lua
+++ b/test/tarantool-tests/lj-1454-ub-os-time.test.lua
@@ -1,7 +1,7 @@
local tap = require('tap')
-- The test file to demonstrate UBSan warning for `os.time()` with
--- a huge indices value for month and/or year.
+-- huge negative index values for month and/or year.
-- See also: https://github.com/LuaJIT/LuaJIT/issues/1454.
local test = tap.test('lj-1454-os-time')
>
>> +-- See also:https://github.com/LuaJIT/LuaJIT/issues/1454.
>> +local test = tap.test('lj-1454-os-time')
> I prefer the lj-1454-ub-os-time name (as you named the branch). Feel
> free to ignore.
Updated:
-- See also: https://github.com/LuaJIT/LuaJIT/issues/1454.
-local test = tap.test('lj-1454-os-time')
+local test = tap.test('lj-1454-ub-os-time')
test:plan(1)
>
>> +
>> +test:plan(1)
>> +
>> +local INT_MIN = -2 ^ 31
>> +
>> +local cur_time = os.time({
>> + day = 1,
>> + month = INT_MIN,
>> + year = INT_MIN,
>> +})
>> +test:is(cur_time, nil, 'os.time() with INT_MIN')
>> +
>> +test:done(true)
>> --
>> 2.43.0
>>
[-- Attachment #2: Type: text/html, Size: 6597 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
2026-06-08 10:59 ` Sergey Bronnikov via Tarantool-patches
@ 2026-06-08 11:03 ` Sergey Kaplun via Tarantool-patches
0 siblings, 0 replies; 8+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2026-06-08 11:03 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: Sergey Bronnikov, tarantool-patches
Sergey,
Thanks for the fixes!
LGTM!
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
2026-06-05 15:18 [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time() Sergey Bronnikov via Tarantool-patches
2026-06-06 7:14 ` Sergey Kaplun via Tarantool-patches
@ 2026-06-11 11:44 ` Evgeniy Temirgaleev via Tarantool-patches
2026-11-06 10:51 ` Sergey Bronnikov via Tarantool-patches
2026-06-11 11:55 ` Evgeniy Temirgaleev via Tarantool-patches
2 siblings, 1 reply; 8+ messages in thread
From: Evgeniy Temirgaleev via Tarantool-patches @ 2026-06-11 11:44 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
[-- Attachment #1: Type: text/plain, Size: 6115 bytes --]
Hi, Sergey! Thanks for the patch!
Please, see my comment.
--
Best regards,
Evgeniy Temirgaleev
>
> From: Sergey Bronnikov <estetus@gmail.com>
> To: tarantool-patches@dev.tarantool.org, Sergey Kaplun <skaplun@tarantool.org
> >, e.temirgaleev@tarantool.org
> Date: Friday, June 5, 2026 6:19 PM +03:00
> From: Mike Pall <mike>
>
> Reported by Sergey Bronnikov.
>
> (cherry picked from commit 86d414f5cae062b06998ec66b0696a47d4f6a0f0)
>
> The function `lj_cf_os_time()` calculates `tm_mon` and `tm_year`
> values using `get_field()` and when the helper function returns
> a negative value the resulted values may be negative as well. This
> is an undefined behaviour (signed integer overflow). The patch fixes
> that by adding a cast for the resulted value to returned by
> `get_field()`.
>
> Sergey Bronnikov:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#12480
> ---
>
> Branch: https://github.com/tarantool/luajit/tree/ligurio/lj-1454-ub-os-time
>
>
> Related issues:
>
> * https://github.com/tarantool/tarantool/issues/12480
> * https://github.com/LuaJIT/LuaJIT/issues/1454
>
> src/lib_os.c | 4 ++--
> test/tarantool-tests/lj-1454-os-time.test.lua | 19 +++++++++++++++++++
> 2 files changed, 21 insertions(+), 2 deletions(-)
> create mode 100644 test/tarantool-tests/lj-1454-os-time.test.lua
>
> diff --git a/src/lib_os.c b/src/lib_os.c
> index ffbc3fdc..0feb0d47 100644
> --- a/src/lib_os.c
> +++ b/src/lib_os.c
> @@ -239,8 +239,8 @@ LJLIB_CF(os_time)
> ts.tm_min = getfield(L, "min", 0);
> ts.tm_hour = getfield(L, "hour", 12);
> ts.tm_mday = getfield(L, "day", -1);
> - ts.tm_mon = getfield(L, "month", -1) - 1;
> - ts.tm_year = getfield(L, "year", -1) - 1900;
> + ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u);
> + ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u);
>
We just suppress signed integer-overflow warning implicitly by casting (and get an unsigned integer-overflow warning instead — try `luajit -e "os.time({ day = 0, month = 0, year = 0 })"` with clang and -fsanitize=integer).
The ignored warning is meaningful in a case, when we get a valid input for mktime() and it returns a valid output for it args, but that result is invalid for args of os.time() due to integer overflow.
I think, the range checks for Lua os.time() args are needed to provide predictable error response. At least, a check for year arg to prevent the invalid result of os.time().
Where are some example calls below (Ubuntu 24, amd64) with some debug printing.
*Not patched version — warning + invalid result*
/src/src/luajit -e "print(os.time({ day = 1, month = 1, year = -2^31 }),'\n')"
lib_os.c:244:42: runtime error: signed integer overflow: -2147483648 - 1900 cannot be represented in type 'int'
lj_cf_os_time: (1) <- ts.tm_mday=1 ts.tm_mon=0 ts.tm_year=2147481748
lj_cf_os_time: (2) -> ts.tm_mday=1 ts.tm_mon=0 ts.tm_year=2147481748 t=67767976233576000 errno=0
6.7767976233576e+16
*Patched version — invalid result only*
/src/src/luajit -e "print(os.time({ day = 1, month = 1, year = -2^31 }),'\n')"
lj_cf_os_time: (1) <- getfield(month)=1 getfield(year)=-2147483648 (u)getfield(month)=0 (u)getfield(year)=2147481748 ts.tm_mday=1 ts.tm_mon=0 ts.tm_year=2147481748
lj_cf_os_time: (2) -> ts.tm_mday=1 ts.tm_mon=0 ts.tm_year=2147481748 t=67767976233576000 errno=0
6.7767976233576e+16
Some more calls for example: the mktime() may ignore invalid tm_mday, tm_mon values of struct tm and update them in a «no error» case.
*Not patched version*
/src/src/luajit -e "print(os.time({ day = -2^31, month = -2^31, year = -2^31+1900 }),'\n')"
lib_os.c:243:42: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
lj_cf_os_time: (1) ts.tm_mday=-2147483648 ts.tm_mon=2147483647 ts.tm_year=-2147483648
lj_cf_os_time: (2) ts.tm_mday=20 ts.tm_mon=0 ts.tm_year=-1974406288 t=-62306246666232000 errno=0
-6.2306246666232e+16
/src/src/luajit -e "print(os.time({ day = -2^31, month = -2^31, year = -2^31+1899 }),'\n')"
lib_os.c:243:42: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
lib_os.c:244:42: runtime error: signed integer overflow: -2147481749 - 1900 cannot be represented in type 'int'
lj_cf_os_time: (1) ts.tm_mday=-2147483648 ts.tm_mon=2147483647 ts.tm_year=2147483647
lj_cf_os_time: (2) ts.tm_mday=-2147483648 ts.tm_mon=2147483647 ts.tm_year=2147483647 t=-1 errno=75
nil
*Patched version*
/src/src/luajit -e "print(os.time({ day = -2^31, month = -2^31, year = -2^31+1900 }),'\n')"
lj_cf_os_time: (1) <- getfield(month)=-2147483648 getfield(year)=-2147481748 (u)getfield(month)=2147483647 (u)getfield(year)=2147483648 ts.tm_mday=-2147483648 ts.tm_mon=2147483647 ts.tm_year=-2147483648
lj_cf_os_time: (2) -> ts.tm_mday=20 ts.tm_mon=0 ts.tm_year=-1974406288 t=-62306246666232000 errno=0
-6.2306246666232e+16
/src/src/luajit -e "print(os.time({ day = -2^31, month = -2^31, year = -2^31+1899 }),'\n')"
lj_cf_os_time: (1) <- getfield(month)=-2147483648 getfield(year)=-2147481749 (u)getfield(month)=2147483647 (u)getfield(year)=2147483647 ts.tm_mday=-2147483648 ts.tm_mon=2147483647 ts.tm_year=2147483647
lj_cf_os_time: (2) -> ts.tm_mday=-2147483648 ts.tm_mon=2147483647 ts.tm_year=2147483647 t=-1 errno=75
nil
>
> ts.tm_isdst = getboolfield(L, "isdst");
> t = mktime(&ts);
> }
> diff --git a/test/tarantool-tests/lj-1454-os-time.test.lua
> b/test/tarantool-tests/lj-1454-os-time.test.lua
> new file mode 100644
> index 00000000..2a48750c
> --- /dev/null
> +++ b/test/tarantool-tests/lj-1454-os-time.test.lua
> @@ -0,0 +1,19 @@
> +local tap = require('tap')
> +
> +-- The test file to demonstrate UBSan warning for `os.time()` with
> +-- a huge indices value for month and/or year.
> +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1454.
> +local test = tap.test('lj-1454-os-time')
> +
> +test:plan(1)
> +
> +local INT_MIN = -2 ^ 31
> +
> +local cur_time = os.time({
> + day = 1,
> + month = INT_MIN,
> + year = INT_MIN,
> +})
> +test:is(cur_time, nil, 'os.time() with INT_MIN')
> +
> +test:done(true)
> --
> 2.43.0
>
[-- Attachment #2: Type: text/html, Size: 8364 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
2026-06-05 15:18 [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time() Sergey Bronnikov via Tarantool-patches
2026-06-06 7:14 ` Sergey Kaplun via Tarantool-patches
2026-06-11 11:44 ` Evgeniy Temirgaleev via Tarantool-patches
@ 2026-06-11 11:55 ` Evgeniy Temirgaleev via Tarantool-patches
2 siblings, 0 replies; 8+ messages in thread
From: Evgeniy Temirgaleev via Tarantool-patches @ 2026-06-11 11:55 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
[-- Attachment #1: Type: text/plain, Size: 3061 bytes --]
Hi, Sergey!
It’s an addition for my previous letter. I am sorry, but the some part of the quote was missed in it.
My single comment is about these lines:
> - ts.tm_mon = getfield(L, "month", -1) - 1;
> - ts.tm_year = getfield(L, "year", -1) - 1900;
> + ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u);
> + ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u);
<please, see the comment text in the first letter>
--
Best regards,
Evgeniy Temirgaleev
>
> From: Sergey Bronnikov <estetus@gmail.com>
> To: tarantool-patches@dev.tarantool.org, Sergey Kaplun <skaplun@tarantool.org
> >, e.temirgaleev@tarantool.org
> Date: Friday, June 5, 2026 6:19 PM +03:00
> From: Mike Pall <mike>
>
> Reported by Sergey Bronnikov.
>
> (cherry picked from commit 86d414f5cae062b06998ec66b0696a47d4f6a0f0)
>
> The function `lj_cf_os_time()` calculates `tm_mon` and `tm_year`
> values using `get_field()` and when the helper function returns
> a negative value the resulted values may be negative as well. This
> is an undefined behaviour (signed integer overflow). The patch fixes
> that by adding a cast for the resulted value to returned by
> `get_field()`.
>
> Sergey Bronnikov:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#12480
> ---
>
> Branch: https://github.com/tarantool/luajit/tree/ligurio/lj-1454-ub-os-time
>
>
> Related issues:
>
> * https://github.com/tarantool/tarantool/issues/12480
> * https://github.com/LuaJIT/LuaJIT/issues/1454
>
> src/lib_os.c | 4 ++--
> test/tarantool-tests/lj-1454-os-time.test.lua | 19 +++++++++++++++++++
> 2 files changed, 21 insertions(+), 2 deletions(-)
> create mode 100644 test/tarantool-tests/lj-1454-os-time.test.lua
>
> diff --git a/src/lib_os.c b/src/lib_os.c
> index ffbc3fdc..0feb0d47 100644
> --- a/src/lib_os.c
> +++ b/src/lib_os.c
> @@ -239,8 +239,8 @@ LJLIB_CF(os_time)
> ts.tm_min = getfield(L, "min", 0);
> ts.tm_hour = getfield(L, "hour", 12);
> ts.tm_mday = getfield(L, "day", -1);
> - ts.tm_mon = getfield(L, "month", -1) - 1;
> - ts.tm_year = getfield(L, "year", -1) - 1900;
> + ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u);
> + ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u);
> ts.tm_isdst = getboolfield(L, "isdst");
> t = mktime(&ts);
> }
> diff --git a/test/tarantool-tests/lj-1454-os-time.test.lua
> b/test/tarantool-tests/lj-1454-os-time.test.lua
> new file mode 100644
> index 00000000..2a48750c
> --- /dev/null
> +++ b/test/tarantool-tests/lj-1454-os-time.test.lua
> @@ -0,0 +1,19 @@
> +local tap = require('tap')
> +
> +-- The test file to demonstrate UBSan warning for `os.time()` with
> +-- a huge indices value for month and/or year.
> +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1454.
> +local test = tap.test('lj-1454-os-time')
> +
> +test:plan(1)
> +
> +local INT_MIN = -2 ^ 31
> +
> +local cur_time = os.time({
> + day = 1,
> + month = INT_MIN,
> + year = INT_MIN,
> +})
> +test:is(cur_time, nil, 'os.time() with INT_MIN')
> +
> +test:done(true)
> --
> 2.43.0
>
[-- Attachment #2: Type: text/html, Size: 4603 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
2026-06-11 11:44 ` Evgeniy Temirgaleev via Tarantool-patches
@ 2026-11-06 10:51 ` Sergey Bronnikov via Tarantool-patches
2026-11-09 2:51 ` Evgeniy Temirgaleev via Tarantool-patches
0 siblings, 1 reply; 8+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2026-11-06 10:51 UTC (permalink / raw)
To: Evgeniy Temirgaleev, Sergey Bronnikov; +Cc: tarantool-patches
[-- Attachment #1: Type: text/plain, Size: 2480 bytes --]
Hi, Evgeniy,
On 6/11/26 14:44, Evgeniy Temirgaleev via Tarantool-patches wrote:
>
> Hi, Sergey! Thanks for the patch!
> Please, see my comment.
> --
> Best regards,
> Evgeniy Temirgaleev
>
> From: Sergey Bronnikov <estetus@gmail.com>
> To: tarantool-patches@dev.tarantool.org, Sergey Kaplun
> <skaplun@tarantool.org>,e.temirgaleev@tarantool.org
> Date: Friday, June 5, 2026 6:19 PM +03:00
> From: Mike Pall <mike>
>
> Reported by Sergey Bronnikov.
>
> (cherry picked from commit 86d414f5cae062b06998ec66b0696a47d4f6a0f0)
>
> The function `lj_cf_os_time()` calculates `tm_mon` and `tm_year`
> values using `get_field()` and when the helper function returns
> a negative value the resulted values may be negative as well. This
> is an undefined behaviour (signed integer overflow). The patch fixes
> that by adding a cast for the resulted value to returned by
> `get_field()`.
>
> Sergey Bronnikov:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#12480
> ---
>
> Branch:
> https://github.com/tarantool/luajit/tree/ligurio/lj-1454-ub-os-time
>
> Related issues:
>
> * https://github.com/tarantool/tarantool/issues/12480
> * https://github.com/LuaJIT/LuaJIT/issues/1454
>
> src/lib_os.c | 4 ++--
> test/tarantool-tests/lj-1454-os-time.test.lua | 19 +++++++++++++++++++
> 2 files changed, 21 insertions(+), 2 deletions(-)
> create mode 100644 test/tarantool-tests/lj-1454-os-time.test.lua
>
> diff --git a/src/lib_os.c b/src/lib_os.c
> index ffbc3fdc..0feb0d47 100644
> --- a/src/lib_os.c
> +++ b/src/lib_os.c
> @@ -239,8 +239,8 @@ LJLIB_CF(os_time)
> ts.tm_min = getfield(L, "min", 0);
> ts.tm_hour = getfield(L, "hour", 12);
> ts.tm_mday = getfield(L, "day", -1);
> - ts.tm_mon = getfield(L, "month", -1) - 1;
> - ts.tm_year = getfield(L, "year", -1) - 1900;
> + ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u);
> + ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u);
>
> We just suppress signed integer-overflow warning implicitly by casting
> (and get an unsigned integer-overflow warning instead —
> try `luajit -e "os.time({ day = 0, month = 0, year = 0 })"` with clang
> and -fsanitize=integer).
Thanks for highlighting this!
I've reported this to upstream [1].
1. https://github.com/LuaJIT/LuaJIT/issues/1454#issuecomment-6683039935
<snipped>
[-- Attachment #2: Type: text/html, Size: 6438 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time().
2026-11-06 10:51 ` Sergey Bronnikov via Tarantool-patches
@ 2026-11-09 2:51 ` Evgeniy Temirgaleev via Tarantool-patches
0 siblings, 0 replies; 8+ messages in thread
From: Evgeniy Temirgaleev via Tarantool-patches @ 2026-11-09 2:51 UTC (permalink / raw)
To: Sergey Bronnikov, Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
The patch is LGTM with the report to upstream. You made a great
discovery for the problem.
As the Mike doesn't want to add new runtime exceptions for os.time() in
the upstream, we may consider to add the check to our port as they are
added in a Lua of higher versions.
I think, Make may worry about consoles, but this is not our case. But on
the other hand, we have a datetime module and may not worry about this
error prone os.date() implementation.
Sergey Kaplun, Sergey Bronnikov, what do you think?
On 11/6/26 1:51 PM, Sergey Bronnikov wrote:
> Hi, Evgeniy,
>
> On 6/11/26 14:44, Evgeniy Temirgaleev via Tarantool-patches wrote:
>>
>> Hi, Sergey! Thanks for the patch!
>> Please, see my comment.
snipped.
>> We just suppress signed integer-overflow warning implicitly by casting
>> (and get an unsigned integer-overflow warning instead —
>> try `luajit -e "os.time({ day = 0, month = 0, year = 0 })"` with clang
>> and -fsanitize=integer).
>
> Thanks for highlighting this!
>
> I've reported this to upstream [1].
>
> 1. https://github.com/LuaJIT/LuaJIT/issues/1454#issuecomment-6683039935
>
> <snipped>
--
--
Best regards,
Evgeniy Temirgaleev
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-09 2:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-05 15:18 [Tarantool-patches] [PATCH luajit] Prevent sanitizer warning in os.time() Sergey Bronnikov via Tarantool-patches
2026-06-06 7:14 ` Sergey Kaplun via Tarantool-patches
2026-06-08 10:59 ` Sergey Bronnikov via Tarantool-patches
2026-06-08 11:03 ` Sergey Kaplun via Tarantool-patches
2026-06-11 11:44 ` Evgeniy Temirgaleev via Tarantool-patches
2026-11-06 10:51 ` Sergey Bronnikov via Tarantool-patches
2026-11-09 2:51 ` Evgeniy Temirgaleev via Tarantool-patches
2026-06-11 11:55 ` Evgeniy Temirgaleev 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