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 64BFF298D22; Fri, 3 Feb 2023 16:29:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 64BFF298D22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1675430952; bh=TKKk2DROLa6uwwnLpr8i4vAvFP9+eT0Wqn8El+77ZUA=; h=Date:In-Reply-To:To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=QGBTJjBPS9jJDuSs5dGPColAjs6vblmeYFq7YbFQnyBaQh+hFwRr+uAXRgMU7gD60 9TxeOncmmLGf2W9xgJkx0P/NVJWXtKO6kdOUZ7TlOXxOv2GMdxszLMGKPfzsV+VkNO T7bu40qGm6EPsmuBaQsCXm9Yfzb+PsuqP97XtnYU= Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [95.163.41.81]) (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 06CA8298D22 for ; Fri, 3 Feb 2023 16:29:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 06CA8298D22 Received: by smtp40.i.mail.ru with esmtpa (envelope-from ) id 1pNw7p-002ofa-Vo; Fri, 03 Feb 2023 16:29:10 +0300 Message-Id: <11D74B84-C7B2-442B-BFE8-8FB39D32FD57@tarantool.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_30DE09D7-2E38-4874-AE6E-2AD92AE3EC7C" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\)) Date: Fri, 3 Feb 2023 16:28:59 +0300 In-Reply-To: To: Sergey Kaplun References: <20230201074651.8282-1-skaplun@tarantool.org> X-Mailer: Apple Mail (2.3731.300.101.1.3) X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9D919194CF4FC660488DBEAA600CFE3E750760201CE27B4E7182A05F538085040547E796F08C9618C22AE1A80E8F7EC22A476528FF4A368D0311757EF5F7DAE4A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7BC08626EA5717D14EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378D70459430292EC88638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8493B9FA76D27202A160F38403D67CEF3117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520599709FD55CB46A6BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4B9100238FE36DC7A2D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE32A336C65186350916E0066C2D8992A16C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637BC468E7E89D8C5D6EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3468964757141B82E0CD3334E0B453364B381F817566CE464C4F0B2E7539FD5F5A1933340C4FF781A71D7E09C32AA3244C48CFF8E6BD337B160E86145B0589E011C3B3ADDA61883BB5FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojdzjlIIgnltY4hB7bNHY04Q== X-Mailru-Sender: 5AA3D5B9D8C486465A7E7C46D91E24B0240A50DA5FB24BAC22AE1A80E8F7EC2238066306E4938E9F60D8632BEC246C7D55B4A2144138A8805FC805B5969CB4993EE16157CC7DAB4272D6B4FCE48DF648AE208404248635DF 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" --Apple-Mail=_30DE09D7-2E38-4874-AE6E-2AD92AE3EC7C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thanks for update! LGTM. Sergos > On 3 Feb 2023, at 11:32, Sergey Kaplun wrote: >=20 > Hi, Sergos! >=20 > Thanks for the review! >=20 > Changed the test as you propose: >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > diff --git a/test/tarantool-tests/lj-463-os-date-oom.test.lua = b/test/tarantool-tests/lj-463-os-date-oom.test.lua > index a39ab6d1..0861ce14 100644 > --- a/test/tarantool-tests/lj-463-os-date-oom.test.lua > +++ b/test/tarantool-tests/lj-463-os-date-oom.test.lua > @@ -4,15 +4,13 @@ local tap =3D require('tap') > local test =3D tap.test('lj-463-os-date-oom') > test:plan(1) >=20 > --- The ru_RU.utf8 locale is chosen as one that will be set on a > --- developer's PC with a 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. > +-- Try all available locales to check the behaviour. > -- 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') > +-- locale (ru_RU.utf8, sv_SE.utf8, etc.) may lead to OOM. > +for locale in io.popen('locale -a'):read('*a'):gmatch('([^\n]*)\n?') = do > + os.setlocale(locale) > + os.date('%p') > +end >=20 > test:ok(true, 'os.date() finished without OOM') > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > Branch is force-pushed. >=20 > On 03.02.23, sergos wrote: >> Hi! >>=20 >> Thanks for the patch! >>=20 >> I can propose to update test with something like >>=20 >> for i in io.popen('locale -a', 'r'):read('*a'):gmatch("([^\n]*)\n?") = do >> os.setlocale(i) >> os.date(%p) >> end >>=20 >> to run the test across all available options. The reason is I got: >>=20 >> tarantool> os.setlocale('ru_RU.utf8') >> --- >> - null >>=20 >> on my system, so I don=E2=80=99t by the =E2=80=98high probability=E2=80= =99.=20 >=20 > Lucky you:). >=20 >>=20 >> Regards, >> Sergos >>=20 >>=20 >>> 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 >=20 > >=20 >>> 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 >>=20 >=20 > --=20 > Best regards, > Sergey Kaplun --Apple-Mail=_30DE09D7-2E38-4874-AE6E-2AD92AE3EC7C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Thanks for = update!

LGTM.

Sergos
<= br>
On 3 Feb 2023, at 11:32, Sergey Kaplun = <skaplun@tarantool.org> wrote:

Hi, Sergos!

Thanks for the = review!

Changed the test as you = propose:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
diff --git = a/test/tarantool-tests/lj-463-os-date-oom.test.lua = b/test/tarantool-tests/lj-463-os-date-oom.test.lua
index a39ab6d1..0861ce14 = 100644
--- = a/test/tarantool-tests/lj-463-os-date-oom.test.lua
+++ = b/test/tarantool-tests/lj-463-os-date-oom.test.lua
@@ -4,15 +4,13 @@ local = tap =3D require('tap')
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 = a 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.
+-- Try = all available locales to check the behaviour.
-- 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')
+-- = locale (ru_RU.utf8, sv_SE.utf8, etc.) may lead to OOM.
+for locale in = io.popen('locale -a'):read('*a'):gmatch('([^\n]*)\n?') do
+ =    os.setlocale(locale)
+ =    os.date('%p')
+end

test:ok(true, 'os.date() finished without OOM')
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Branch is = force-pushed.

On 03.02.23, sergos = wrote:
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)
   &= nbsp; 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. 

Lucky you:).


Regards,
Sergos


On 1 = Feb 2023, at 10:46, Sergey Kaplun <skaplun@tarantool.org> = wrote:

From: Mike Pall <mike>

Thanks to Jesper = Lundgren.

(cherry picked from commit = fc63c938b522e147ea728b75f385728bf4a8fc35)

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.

This = patch limits amount of retries by 4.

Sergey Kaplun:
* added = the description and the test for the problem

Part of = tarantool/tarantool#8069
---

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

src/lib_os.c =             &n= bsp;           &nbs= p;        |  4 = ++--
.../lj-463-os-date-oom.test.lua =             &n= bsp; | 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

<snipped>

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/Lu= aJIT/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:o= k(true, 'os.date() finished without OOM')
+
+os.exit(test:check() = and 0 or 1)
-- 
2.34.1



-- 
Best regards,
Sergey = Kaplun

= --Apple-Mail=_30DE09D7-2E38-4874-AE6E-2AD92AE3EC7C--