From 3d9ec159cb362d71cf76938d583841975b3e730a Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sat, 25 Feb 2023 12:41:25 -0800 Subject: Improve lexing of invalid annotations (#2150) This had been crashing even with annotations disabled. Adds a regression test. This was missed in #2001 when updating the lexer to match the updated spec (WebAssembly/spec#1499). Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53935 --- src/wast-lexer.cc | 2 +- test/regress/bad-annotation.txt | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/regress/bad-annotation.txt diff --git a/src/wast-lexer.cc b/src/wast-lexer.cc index cc3d2751..dbdee9aa 100644 --- a/src/wast-lexer.cc +++ b/src/wast-lexer.cc @@ -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 { diff --git a/test/regress/bad-annotation.txt b/test/regress/bad-annotation.txt new file mode 100644 index 00000000..c3a3b0bf --- /dev/null +++ b/test/regress/bad-annotation.txt @@ -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 ;;) -- cgit v1.2.3