From 978890e7f66a7e8c341f0711ddc249b3f45386a8 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Mon, 17 Nov 2025 18:20:29 +0900 Subject: [PATCH] feat(parserstmt): add shallow recursion guard to ParserStmtBox.parse --- lang/src/compiler/parser/stmt/parser_stmt_box.hako | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lang/src/compiler/parser/stmt/parser_stmt_box.hako b/lang/src/compiler/parser/stmt/parser_stmt_box.hako index b7763e45..b8ecbb25 100644 --- a/lang/src/compiler/parser/stmt/parser_stmt_box.hako +++ b/lang/src/compiler/parser/stmt/parser_stmt_box.hako @@ -9,6 +9,17 @@ using lang.compiler.parser.stmt.parser_exception_box static box ParserStmtBox { parse(src, i, ctx) { + // Shallow recursion guard: prevent ParserStmtBox.parse from recursively + // re-entering itself on the same VM stack(Stage‑B/selfhost 安全弁)。 + { + local depth = env.get("HAKO_STAGEB_STMT_DEPTH") + if depth != null && ("" + depth) != "0" { + print("[stageb/recursion] ParserStmtBox.parse recursion detected") + // Fail-fast: return empty stmt and keep position unchanged + return "" + } + env.set("HAKO_STAGEB_STMT_DEPTH", "1") + } local j = ctx.skip_ws(src, i) local stmt_start = j @@ -182,6 +193,8 @@ static box ParserStmtBox { if j < src.length() { j = j + 1 } else { j = src.length() } } ctx.gpos_set(j) + // Clear depth guard before returning + env.set("HAKO_STAGEB_STMT_DEPTH", "0") return "{\"type\":\"Expr\",\"expr\":" + e + "}" }