summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Lublinerman <rluble@google.com>2024-03-19 15:04:47 -0700
committerGitHub <noreply@github.com>2024-03-19 22:04:47 +0000
commitf9dc56913085eb7c2565047d87ca84b84a837518 (patch)
treec6cb2c6163999c1bfb2e57ed8f400175476315cd
parent4ce9fb460b6a1161209904264bafec96abe911ac (diff)
downloadbinaryen-f9dc56913085eb7c2565047d87ca84b84a837518.tar.gz
binaryen-f9dc56913085eb7c2565047d87ca84b84a837518.tar.bz2
binaryen-f9dc56913085eb7c2565047d87ca84b84a837518.zip
[Strings] Avoid mishandling unicode in StringConcat (#6411)
-rw-r--r--src/wasm-interpreter.h5
-rw-r--r--test/lit/passes/precompute-strings.wast28
2 files changed, 32 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index af01865f4..36542e6ed 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1959,6 +1959,11 @@ public:
if (!leftData || !rightData) {
trap("null ref");
}
+ // This is only correct if all the bytes in the left operand correspond
+ // to single unicode code points.
+ if (hasNonAsciiUpTo(leftData->values)) {
+ return Flow(NONCONSTANT_FLOW);
+ }
Literals contents;
contents.reserve(leftData->values.size() + rightData->values.size());
diff --git a/test/lit/passes/precompute-strings.wast b/test/lit/passes/precompute-strings.wast
index f70430648..c9facfe36 100644
--- a/test/lit/passes/precompute-strings.wast
+++ b/test/lit/passes/precompute-strings.wast
@@ -1,11 +1,21 @@
-;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: wasm-opt %s --precompute -all -S -o - | filecheck %s
(module
+ ;; CHECK: (type $0 (func (result i32)))
+
+ ;; CHECK: (type $1 (func (result (ref string))))
+
;; CHECK: (type $array16 (array (mut i16)))
(type $array16 (array (mut i16)))
+ ;; CHECK: (export "get_codepoint-bad" (func $get_codepoint-bad))
+
+ ;; CHECK: (export "slice" (func $slice))
+
+ ;; CHECK: (export "slice-bad" (func $slice-bad))
+
;; CHECK: (func $eq-no (type $0) (result i32)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
@@ -36,6 +46,22 @@
)
)
+ ;; CHECK: (func $concat-bad (type $0) (result i32)
+ ;; CHECK-NEXT: (string.eq
+ ;; CHECK-NEXT: (string.concat
+ ;; CHECK-NEXT: (string.const "a\f0")
+ ;; CHECK-NEXT: (string.const "b")
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (string.const "a\f0b")
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $concat-bad (result i32)
+ (string.eq
+ (string.concat (string.const "a\F0") (string.const "b"))
+ (string.const "a\F0b")
+ )
+ )
+
;; CHECK: (func $length (type $0) (result i32)
;; CHECK-NEXT: (i32.const 7)
;; CHECK-NEXT: )