authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2026-07-06 12:34:45+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2026-07-08 11:49:01+02:00
log010a98dbfce6f42ae12fda09060e37748e58dc2d
tree1b34de49ecb74f758b8fe857404893bdc30761ab
parent87d695e4d910e337d611a2a92b01c805e1588c8d
signaturelock-open Commit is signed but in an unrecognized format.

parser: avoid extra parsing when recovery disabled

Currently in a special case the parser will keep parsing after it has been determined that there is a parse error in order to give a more user-friendly error message. However, this opens the parser up to stack overflow when fuzzing, so skip the extra parsing and potentially better error message when recovery is disabled.

1 files changed, 11 insertions(+), 7 deletions(-)

lib/std/zig/Parse.zig+11-7
...@@ -1249,13 +1249,17 @@ fn parseLabeledStatement(p: *Parse) !?Node.Index {...@@ -1249,13 +1249,17 @@ fn parseLabeledStatement(p: *Parse) !?Node.Index {
1249 const label_token = opt_label_token orelse return null;1249 const label_token = opt_label_token orelse return null;
12501250
1251 const after_colon = p.tok_i;1251 const after_colon = p.tok_i;
1252 if (try p.parseTypeExpr()) |_| {1252 // Don't bother trying to give a better error message if recovery is disabled.
1253 const a = try p.parseByteAlign();1253 // This avoids a possible stack overflow in e.g. parseTypeExpr() when fuzzing.
1254 const b = try p.parseAddrSpace();1254 if (p.recover) {
1255 const c = try p.parseLinkSection();1255 if (try p.parseTypeExpr()) |_| {
1256 const d = if (p.eatToken(.equal) == null) null else try p.expectExpr();1256 const a = try p.parseByteAlign();
1257 if (a != null or b != null or c != null or d != null) {1257 const b = try p.parseAddrSpace();
1258 return p.failMsg(.{ .tag = .expected_var_const, .token = label_token });1258 const c = try p.parseLinkSection();
1259 const d = if (p.eatToken(.equal) == null) null else try p.expectExpr();
1260 if (a != null or b != null or c != null or d != null) {
1261 return p.failMsg(.{ .tag = .expected_var_const, .token = label_token });
1262 }
1259 }1263 }
1260 }1264 }
1261 return p.failMsg(.{ .tag = .expected_labelable, .token = after_colon });1265 return p.failMsg(.{ .tag = .expected_labelable, .token = after_colon });