From 1d75cd4d7be638babe6d4e47bf73ea05fc65d81c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 27 Nov 2022 15:25:32 +0100 Subject: [PATCH] Avoid assertion in case of stack overflow from stitched trace. Reported by Sergey Bronnikov. Fixed by Sergey Kaplun. --- src/lj_debug.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lj_debug.c b/src/lj_debug.c index 112f5358..ca893153 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c @@ -101,9 +101,12 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe) pos = proto_bcpos(pt, ins) - 1; #if LJ_HASJIT if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */ - GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); - lj_assertL(bc_isret(bc_op(ins[-1])), "return bytecode expected"); - pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); + if (bc_isret(bc_op(ins[-1]))) { + GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); + pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); + } else { + pos = NO_BCPOS; /* Punt in case of stack overflow for stitched trace. */ + } } #endif return pos;