summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-06-18 20:08:25 -0700
committerGitHub <noreply@github.com>2024-06-19 03:08:25 +0000
commit765c61445550c6e4ecfd250e1893d776d570b4fd (patch)
treeab60cbac0ba59fa649d93e9b62a2c0b0b0915a69 /src/parser
parent3acacac34c9ebe949fbc7d9eb3649266760104fe (diff)
downloadbinaryen-765c61445550c6e4ecfd250e1893d776d570b4fd.tar.gz
binaryen-765c61445550c6e4ecfd250e1893d776d570b4fd.tar.bz2
binaryen-765c61445550c6e4ecfd250e1893d776d570b4fd.zip
Validate that names are valid UTF-8 (#6682)
Add an `isUTF8` utility and use it in both the text and binary parsers. Add missing checks for overlong encodings and overlarge code points in our WTF8 reader, which the new utility uses. Re-enable the spec tests that test UTF-8 validation.
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/lexer.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/parser/lexer.h b/src/parser/lexer.h
index 83cbcfc53..37c3fe04a 100644
--- a/src/parser/lexer.h
+++ b/src/parser/lexer.h
@@ -25,6 +25,7 @@
#include "support/name.h"
#include "support/result.h"
+#include "support/string.h"
#ifndef parser_lexer_h
#define parser_lexer_h
@@ -124,11 +125,11 @@ public:
std::optional<std::string> takeString();
std::optional<Name> takeName() {
- // TODO: Validate UTF.
- if (auto str = takeString()) {
- return Name(*str);
+ auto str = takeString();
+ if (!str || !String::isUTF8(*str)) {
+ return std::nullopt;
}
- return std::nullopt;
+ return Name(*str);
}
bool takeSExprStart(std::string_view expected) {