From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 651316ECCC; Fri, 3 Feb 2023 01:29:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 651316ECCC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1675376947; bh=mxsLBO8PnhVlXL7eWX8Oy/feoXZTPeLW1Pqh8PfIdhw=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=keWWPMqUnLZLabvWWCslb6rSNFZrOvSWnPOAkODsV5r2jj6AKDc9YVhKLJIWbjGNR KZyRgYwkCAcUegh1g632akXAjdM/wXWXPpEgnPOUILQy7/nmujMtJb9wS4puicb8Up DvBz6MyJB/pYPlrVhoCH5mdDL5iJuRsXuHH0JEHc= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 3D24D6ECCC for ; Fri, 3 Feb 2023 01:29:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3D24D6ECCC Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1pNi4m-0002c2-EB; Fri, 03 Feb 2023 01:29:04 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\)) In-Reply-To: <20230201074651.8282-1-skaplun@tarantool.org> Date: Fri, 3 Feb 2023 01:28:53 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20230201074651.8282-1-skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3731.300.101.1.3) X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D919194CF4FC6604A01E0973C23BD86EDECBF287589C38D0182A05F5380850401FC4045639CC1067E0E81E7A14EAD14AE85A032D3B74FF28E55103D5842606C1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7544B1CCE26E01C74EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EA9DEEAA3ECF8E948638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81B6FF965FC70A1628D3A36CF319BE17A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520C24E1E72F37C03A0C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4B7AAF5A6EB0CB4C2AD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE32A336C65186350916E0066C2D8992A16C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637BBEA499411984DA1EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343FB425EC7F4D4A4B0F4FF4E8EC8772C89CC61A7396FC74EA684D371DD67D17ECE99D7973B521AE621D7E09C32AA3244CF98F5882987498126890A71C6F64D18C795D98D676DD64D0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojUCXb8yEWKAmh5a1kUDKpAQ== X-Mailru-Sender: 5AA3D5B9D8C486465A7E7C46D91E24B0742B422A92942C3DE0E81E7A14EAD14A84876E3DC5E244DF60D8632BEC246C7D55B4A2144138A8805FC805B5969CB4993EE16157CC7DAB4272D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix os.date() for wider libc strftime() compatibility. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: sergos via Tarantool-patches Reply-To: sergos Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! I can propose to update test with something like for i in io.popen('locale -a', 'r'):read('*a'):gmatch("([^\n]*)\n?") = do os.setlocale(i) os.date(%p) end to run the test across all available options. The reason is I got: tarantool> os.setlocale('ru_RU.utf8') --- - null on my system, so I don=E2=80=99t by the =E2=80=98high probability=E2=80=99= .=20 Regards, Sergos > On 1 Feb 2023, at 10:46, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > Thanks to Jesper Lundgren. >=20 > (cherry picked from commit fc63c938b522e147ea728b75f385728bf4a8fc35) >=20 > When `strftime()` returns empty result (for example, for "%p" on some > locales or when LuaJIT is built with musl's `strftime()` and format > string is invalid), the `os.date()` endless retries to format result > and reallocates buffer for resulting string. This leads to OOM. >=20 > This patch limits amount of retries by 4. >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > Part of tarantool/tarantool#8069 > --- >=20 > PR: https://github.com/tarantool/tarantool/pull/8237 > Issues: > * https://github.com/LuaJIT/LuaJIT/issues/463 > * https://github.com/tarantool/tarantool/issues/8069 > Branch: = https://github.com/tarantool/luajit/tree/skaplun/lj-463-os-date-oom-full-c= i >=20 > 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 >=20 > 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 =3D &G(L)->tmpbuf; > - MSize sz =3D 0; > + MSize sz =3D 0, retry =3D 4; > const char *q; > for (q =3D s; *q; q++) > sz +=3D (*q =3D=3D '%') ? 30 : 1; /* Overflow doesn't matter. = */ > setsbufL(sb, L); > - for (;;) { > + while (retry--) { /* Limit growth for invalid format or empty = result. */ > char *buf =3D lj_buf_need(sb, sz); > size_t len =3D 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 =3D require('tap') > + > +-- See also https://github.com/LuaJIT/LuaJIT/issues/463. > +local test =3D 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 > +-- CI, so don't check the status and result of function calls. > +-- If it's unavailable `os.setlocale()` does nothing. > +-- Before the patch, the call to `os.date('%p')` on non-standard > +-- locale may lead to OOM. > + > +os.setlocale('ru_RU.utf8') > +os.date('%p') > + > +test:ok(true, 'os.date() finished without OOM') > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.34.1 >=20