summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-03-26 10:44:37 -0700
committerGitHub <noreply@github.com>2024-03-26 10:44:37 -0700
commit431e858c4f4ac0343914eb42196f8bb64ac99023 (patch)
tree7071e42b72b2cb49c9a15845c5fe1675d3ebd4bf /src
parentc9a5da466df084da5c0bbcb03b56aa1bd9585dcd (diff)
downloadbinaryen-431e858c4f4ac0343914eb42196f8bb64ac99023.tar.gz
binaryen-431e858c4f4ac0343914eb42196f8bb64ac99023.tar.bz2
binaryen-431e858c4f4ac0343914eb42196f8bb64ac99023.zip
[Strings] Escape strings printed by fuzz-exec (#6441)
Previously we printed strings as WTF-8 in the output of fuzz-exec, but this could produce invalid unicode output and did not make unprintable characters visible. Fix both these problems by escaping the output, using the JSON string escape procedure since the string to be escaped is WTF-16. Reimplement the same escaping procedure in fuzz_shell.js so that the way we print strings when running on a real JS engine matches the way we print them in our own fuzz-exec interpreter. Fixes #6435.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/literal.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index afdc14c72..887c777ec 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -639,7 +639,7 @@ std::ostream& operator<<(std::ostream& o, Literal literal) {
if (!data) {
o << "nullstring";
} else {
- o << "string(\"";
+ o << "string(";
// Convert WTF-16 literals to WTF-16 string.
std::stringstream wtf16;
for (auto c : data->values) {
@@ -648,12 +648,11 @@ std::ostream& operator<<(std::ostream& o, Literal literal) {
wtf16 << uint8_t(u & 0xFF);
wtf16 << uint8_t(u >> 8);
}
- // Convert to WTF-8 for printing.
+ // Escape to ensure we have valid unicode output and to make
+ // unprintable characters visible.
// TODO: Use wtf16.view() once we have C++20.
- [[maybe_unused]] bool valid =
- String::convertWTF16ToWTF8(o, wtf16.str());
- assert(valid);
- o << "\")";
+ String::printEscapedJSON(o, wtf16.str());
+ o << ")";
}
break;
}