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 22AD9281E76; Thu, 2 Feb 2023 22:32:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 22AD9281E76 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1675366343; bh=h6quT622js7pnw/sd2K0q+j6IaNuvXtDPB/12J8yI48=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=BBdfAJDjSeWCt3cWUT0qYZJtZdpNqYWYCdMMdd3os+tPqTacYIr3UH1yU4QMJI7Vd An8o6C5Gi1vFY+SQzAHbI2/rza4z2wnacFKjKy87KGCHLkT3/DUrB2J6qxxD/6PaUN x0ZPAe6dW4UsvnaF712ofClw8oA1CwMSckhIO9Hk= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 14DC2128C1 for ; Thu, 2 Feb 2023 22:32:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 14DC2128C1 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1pNfJk-0004WG-1N; Thu, 02 Feb 2023 22:32:20 +0300 Date: Thu, 2 Feb 2023 22:28:52 +0300 To: Maxim Kokryashkin Message-ID: References: <20230201074651.8282-1-skaplun@tarantool.org> <1675294884.480320482@f477.i.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1675294884.480320482@f477.i.mail.ru> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9D919194CF4FC660488DBEAA600CFE3E750760201CE27B4E7182A05F538085040F1F48784745F698DD1B49AC1957DFA61DC77304A376C0CA187F1AB0201ADC80D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F1942E6D70B4A2F0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377845AD97F799C6E88638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8551D269A9945F059BC419E43EB0A4928117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC292D688DDAD4E7BC389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8F8BD4E506CFA3D88F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B08F9A42B2210255C75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34EE19B6E2433CA093E63755EA425F46BFC7B97B359E014E57ED9CC14D4D24EF5C79144B0EF206EC8C1D7E09C32AA3244C30241B3D179521C7DF471C6FCC33940669B6CAE0477E908DFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojUCXb8yEWKAkKX2uIYyxPYQ== X-DA7885C5: 9EA46B6E49B3F282E0EC73950DBD5B161E520C99A747E4E75E8FE5F96C6406F1262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73933AF1F914F131DBF52A2388A4FBB7D36C128DE8C0BFFD53E80FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim! Thanks for the review! Fixed your comments, branch is force-pushed. On 02.02.23, Maxim Kokryashkin wrote: > > Hi, Sergey! > Thanks for the patch! > LGTM, except for a few nits below. > >  > >>From: Mike Pall > >> > >>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 > >Typo: s/endless/endlessly/ > >Typo: s/format result/format the result/ Fixed, thanks! > >>and reallocates buffer for resulting string. This leads to OOM. > >Typo: s/buffer for resulting/the buffer for the resulting/ Fixed, thanks! > >> > >>This patch limits amount of retries by 4. > >Typo: s/amount/the amount/ Fixed, thanks! > >Side note: Why is it exactly 4? That's what she said:) > >> > >>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-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 > >Typo: s/with high possibility/with a high probability/ Fixed. > >>+-- 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) > >>-- > >>2.34.1 > >-- > >Best regards, > >Maxim Kokryashkin > >  -- Best regards, Sergey Kaplun