Skip to content

Commit 1b426ea

Browse files
osa1Commit Queue
authored and
Commit Queue
committed
[dart2wasm] Fix string array copy in UTF8 decoder
Bug introduced with [1] and broke the Flutter engine [2]. [1]: https://dart-review.googlesource.com/c/sdk/+/331187 [2]: flutter/flutter#137120 Change-Id: I334db1bbf1440b53b7a7856f16a0e116d82efae5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331922 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]>
1 parent 75920dd commit 1b426ea

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

sdk/lib/_internal/wasm/lib/convert_patch.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,8 @@ class _Utf8Decoder {
17361736
// Pure ASCII.
17371737
assert(size == end - start);
17381738
OneByteString result = OneByteString.withLength(size);
1739-
oneByteStringArray(result).copy(0, bytes.data, start, size);
1739+
oneByteStringArray(result)
1740+
.copy(0, bytes.data, bytes.offsetInBytes + start, size);
17401741
return result;
17411742
}
17421743

tests/lib/convert/utf8_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ void testDecodeSlice() {
3232
Expect.equals("BCD", decoder.convert(ascii, 1, 4));
3333
Expect.equals("ABCD", decoder.convert(ascii, 0, 4));
3434

35+
if (ascii is Uint8List) {
36+
Expect.equals("ABCDE", decoder.convert(Uint8List.sublistView(ascii, 0)));
37+
Expect.equals("ABCDE",
38+
decoder.convert(Uint8List.sublistView(ascii, 0, ascii.length)));
39+
Expect.equals("CDE", decoder.convert(Uint8List.sublistView(ascii, 2)));
40+
Expect.equals("BCD", decoder.convert(Uint8List.sublistView(ascii, 1, 4)));
41+
Expect.equals(
42+
"ABCD", decoder.convert(Uint8List.sublistView(ascii, 0, 4)));
43+
}
44+
3545
Expect.throws(() => decoder.convert(ascii, -1)); // start < 0.
3646
Expect.throws(() => decoder.convert(ascii, 6)); // start > length
3747
Expect.throws(() => decoder.convert(ascii, 0, -1)); // end < 0
@@ -48,6 +58,18 @@ void testDecodeSlice() {
4858
Expect.equals("\u0082\u1041", decoder.convert(utf8, 2));
4959
Expect.equals("\u0081\u0082", decoder.convert(utf8, 0, 4));
5060
Expect.equals("\u0082", decoder.convert(utf8, 2, 4));
61+
62+
if (utf8 is Uint8List) {
63+
Expect.equals("\u0081\u0082\u1041",
64+
decoder.convert(Uint8List.sublistView(utf8, 0)));
65+
Expect.equals(
66+
"\u0082\u1041", decoder.convert(Uint8List.sublistView(utf8, 2)));
67+
Expect.equals(
68+
"\u0081\u0082", decoder.convert(Uint8List.sublistView(utf8, 0, 4)));
69+
Expect.equals(
70+
"\u0082", decoder.convert(Uint8List.sublistView(utf8, 2, 4)));
71+
}
72+
5173
Expect.throws(() => decoder.convert(utf8, 1));
5274
Expect.throws(() => decoder.convert(utf8, 0, 1));
5375
Expect.throws(() => decoder.convert(utf8, 2, 5));

0 commit comments

Comments
 (0)