Skip to content

Commit

Permalink
Improve parsing of invalid annotations
Browse files Browse the repository at this point in the history
This had been crashing even with annotations disabled.
Adds a regression test.

This was missed in #2001 when updating the parser to match
the updated spec (WebAssembly/spec#1499).

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53935
  • Loading branch information
keithw committed Feb 25, 2023
1 parent adc9ecc commit 478b0a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wast-lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Token WastLexer::GetToken() {
}
return BareToken(TokenType::Eof);
} else if (MatchString("(@")) {
ReadReservedChars();
GetIdToken();
// offset=2 to skip the "(@" prefix
return TextToken(TokenType::LparAnn, 2);
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/regress/bad-annotation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;;; TOOL: wat2wasm
;;; ERROR: 1
(@"annotation
(;; STDERR ;;;
out/test/regress/bad-annotation.txt:3:1: error: annotations not enabled: "annotation
(@"annotation
^^^^^^^^^^^^^
out/test/regress/bad-annotation.txt:3:1: error: unexpected token "Invalid", expected a module field or a module.
(@"annotation
^^^^^^^^^^^^^
;;; STDERR ;;)

0 comments on commit 478b0a9

Please sign in to comment.