<HTML><BODY><div>Hi, Sergey!</div><div>Thanks for the review!</div><div>Tested on GC64 and non-GC64, and Linux/MacOS builds — test fails</div><div>before the patch everywhere.</div><div>Tested with API check and assertions enabled.</div><div data-signature-widget="container"><div data-signature-widget="content"><div>--<br>Best regards,</div><div>Maxim Kokryashkin</div></div></div><div> </div><div> </div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">Пятница, 24 ноября 2023, 15:34 +03:00 от Sergey Bronnikov <sergeyb@tarantool.org>:<br> <div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_17008292741355240530_BODY">Hello, Max<br><br>added testcase is passed with reverted patch<br><br>Sergey<br><br>On 11/22/23 17:35, Maksim Kokryashkin wrote:<div class="mail-quote-collapse">> From: Mike Pall <mike><br>><br>> (cherry-picked from commit aa6b15c1a8922848bd6f596ba384824ca3fe0f5f)<br>><br>> The stack overflow error is thrown in `lj_state_growstack` only<br>> if the coroutine status is `OK`, however, stack overflow can<br>> happen on a yielded coroutine too. This patch fixes the condition<br>> for status, so now the error thrown on yielded coroutines too.<br>><br>> Maxim Kokryashkin:<br>> * added the description and the test for the patch<br>><br>> Part of tarantool/tarantool#9145<br>> ---<br>> src/lj_state.c | 2 +-<br>> .../lj-962-premature-stack-overflow.test.c | 23 +++++++++++++++++++<br>> 2 files changed, 24 insertions(+), 1 deletion(-)<br>><br>> diff --git a/src/lj_state.c b/src/lj_state.c<br>> index d8a5134c..01d4901a 100644<br>> --- a/src/lj_state.c<br>> +++ b/src/lj_state.c<br>> @@ -126,7 +126,7 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)<br>> if (L->stacksize > LJ_STACK_MAXEX)<br>> lj_err_throw(L, LUA_ERRERR); /* Does not invoke an error handler. */<br>> /* 1. We are _at_ the limit after the last growth. */<br>> - if (!L->status) { /* 2. Throw 'stack overflow'. */<br>> + if (L->status < LUA_ERRRUN) { /* 2. Throw 'stack overflow'. */<br>> L->status = LUA_ERRRUN; /* Prevent ending here again for pushed msg. */<br>> lj_err_msg(L, LJ_ERR_STKOV); /* May invoke an error handler. */<br>> }<br>> diff --git a/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c b/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c<br>> index 12cb9004..461e0ccc 100644<br>> --- a/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c<br>> +++ b/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c<br>> @@ -24,6 +24,20 @@ static int fill_stack(lua_State *L)<br>> return 0;<br>> }<br>><br>> +static int immediate_yield(lua_State *L)<br>> +{<br>> + return lua_yield(L, 0);<br>> +}<br>> +<br>> +static int overflow_suspended_coro(lua_State *L)<br>> +{<br>> + lua_State *newL = lua_newthread(L);<br>> + lua_pushcfunction(newL, immediate_yield);<br>> + lua_resume(newL, 0);<br>> + fill_stack(newL);<br>> + return 0;<br>> +}<br>> +<br>> static int premature_stackoverflow(void *test_state)<br>> {<br>> lua_State *L = test_state;<br>> @@ -50,12 +64,21 @@ static int stackoverflow_during_stackoverflow(void *test_state)<br>> return TEST_EXIT_SUCCESS;<br>> }<br>><br>> +static int stackoverflow_on_suspended_coro(void *test_state)<br>> +{<br>> + lua_State *L = test_state;<br>> + int status = lua_cpcall(L, overflow_suspended_coro, NULL);<br>> + assert_true(status == LUA_ERRRUN);<br>> + return TEST_EXIT_SUCCESS;<br>> +}<br>> +<br>> int main(void)<br>> {<br>> lua_State *L = utils_lua_init();<br>> const struct test_unit tgroup[] = {<br>> test_unit_def(premature_stackoverflow),<br>> test_unit_def(stackoverflow_during_stackoverflow),<br>> + test_unit_def(stackoverflow_on_suspended_coro),<br>> };<br>> const int test_result = test_run_group(tgroup, L);<br>> utils_lua_close(L);</div></div></div></div></div></blockquote><div> </div></BODY></HTML>