Skip to content

Commit f9dc569

Browse files
authored
[Strings] Avoid mishandling unicode in StringConcat (#6411)
1 parent 4ce9fb4 commit f9dc569

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/wasm-interpreter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,11 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
19591959
if (!leftData || !rightData) {
19601960
trap("null ref");
19611961
}
1962+
// This is only correct if all the bytes in the left operand correspond
1963+
// to single unicode code points.
1964+
if (hasNonAsciiUpTo(leftData->values)) {
1965+
return Flow(NONCONSTANT_FLOW);
1966+
}
19621967

19631968
Literals contents;
19641969
contents.reserve(leftData->values.size() + rightData->values.size());

test/lit/passes/precompute-strings.wast

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
22

33
;; RUN: wasm-opt %s --precompute -all -S -o - | filecheck %s
44

55
(module
6+
;; CHECK: (type $0 (func (result i32)))
7+
8+
;; CHECK: (type $1 (func (result (ref string))))
9+
610
;; CHECK: (type $array16 (array (mut i16)))
711
(type $array16 (array (mut i16)))
812

13+
;; CHECK: (export "get_codepoint-bad" (func $get_codepoint-bad))
14+
15+
;; CHECK: (export "slice" (func $slice))
16+
17+
;; CHECK: (export "slice-bad" (func $slice-bad))
18+
919
;; CHECK: (func $eq-no (type $0) (result i32)
1020
;; CHECK-NEXT: (i32.const 0)
1121
;; CHECK-NEXT: )
@@ -36,6 +46,22 @@
3646
)
3747
)
3848

49+
;; CHECK: (func $concat-bad (type $0) (result i32)
50+
;; CHECK-NEXT: (string.eq
51+
;; CHECK-NEXT: (string.concat
52+
;; CHECK-NEXT: (string.const "a\f0")
53+
;; CHECK-NEXT: (string.const "b")
54+
;; CHECK-NEXT: )
55+
;; CHECK-NEXT: (string.const "a\f0b")
56+
;; CHECK-NEXT: )
57+
;; CHECK-NEXT: )
58+
(func $concat-bad (result i32)
59+
(string.eq
60+
(string.concat (string.const "a\F0") (string.const "b"))
61+
(string.const "a\F0b")
62+
)
63+
)
64+
3965
;; CHECK: (func $length (type $0) (result i32)
4066
;; CHECK-NEXT: (i32.const 7)
4167
;; CHECK-NEXT: )

0 commit comments

Comments
 (0)