Sergey Kaplun:
* added the description and the test for the problem
Part of tarantool/tarantool#8069
---
PR:
https://github.com/tarantool/tarantool/pull/8237Issues:
*
https://github.com/LuaJIT/LuaJIT/issues/463*
https://github.com/tarantool/tarantool/issues/8069Branch:
https://github.com/tarantool/luajit/tree/skaplun/lj-463-os-date-oom-full-ci src/lib_os.c | 4 ++--
.../lj-463-os-date-oom.test.lua | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
create mode 100644 test/tarantool-tests/lj-463-os-date-oom.test.lua
diff --git a/src/lib_os.c b/src/lib_os.c
index 9e78d49a..ffbc3fdc 100644
--- a/src/lib_os.c
+++ b/src/lib_os.c
@@ -205,12 +205,12 @@ LJLIB_CF(os_date)
setboolfield(L, "isdst", stm->tm_isdst);
} else if (*s) {
SBuf *sb = &G(L)->tmpbuf;
- MSize sz = 0;
+ MSize sz = 0, retry = 4;
const char *q;
for (q = s; *q; q++)
sz += (*q == '%') ? 30 : 1; /* Overflow doesn't matter. */
setsbufL(sb, L);
- for (;;) {
+ while (retry--) { /* Limit growth for invalid format or empty result. */
char *buf = lj_buf_need(sb, sz);
size_t len = strftime(buf, sbufsz(sb), s, stm);
if (len) {
diff --git a/test/tarantool-tests/lj-463-os-date-oom.test.lua b/test/tarantool-tests/lj-463-os-date-oom.test.lua
new file mode 100644
index 00000000..cce78b6e
--- /dev/null
+++ b/test/tarantool-tests/lj-463-os-date-oom.test.lua
@@ -0,0 +1,19 @@
+local tap = require('tap')
+
+-- See also
https://github.com/LuaJIT/LuaJIT/issues/463.
+local test = tap.test('lj-463-os-date-oom')
+test:plan(1)
+
+-- The ru_RU.utf8 locale is chosen as one that will be set on a
+-- developer's PC with high possibility. It may be unavailable at