mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 16:00:45 +00:00
[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]: https://github.com/flutter/flutter/issues/137120 Change-Id: I334db1bbf1440b53b7a7856f16a0e116d82efae5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331922 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
parent
75920dd24b
commit
1b426ea6f8
|
@ -1736,7 +1736,8 @@ class _Utf8Decoder {
|
|||
// Pure ASCII.
|
||||
assert(size == end - start);
|
||||
OneByteString result = OneByteString.withLength(size);
|
||||
oneByteStringArray(result).copy(0, bytes.data, start, size);
|
||||
oneByteStringArray(result)
|
||||
.copy(0, bytes.data, bytes.offsetInBytes + start, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,16 @@ void testDecodeSlice() {
|
|||
Expect.equals("BCD", decoder.convert(ascii, 1, 4));
|
||||
Expect.equals("ABCD", decoder.convert(ascii, 0, 4));
|
||||
|
||||
if (ascii is Uint8List) {
|
||||
Expect.equals("ABCDE", decoder.convert(Uint8List.sublistView(ascii, 0)));
|
||||
Expect.equals("ABCDE",
|
||||
decoder.convert(Uint8List.sublistView(ascii, 0, ascii.length)));
|
||||
Expect.equals("CDE", decoder.convert(Uint8List.sublistView(ascii, 2)));
|
||||
Expect.equals("BCD", decoder.convert(Uint8List.sublistView(ascii, 1, 4)));
|
||||
Expect.equals(
|
||||
"ABCD", decoder.convert(Uint8List.sublistView(ascii, 0, 4)));
|
||||
}
|
||||
|
||||
Expect.throws(() => decoder.convert(ascii, -1)); // start < 0.
|
||||
Expect.throws(() => decoder.convert(ascii, 6)); // start > length
|
||||
Expect.throws(() => decoder.convert(ascii, 0, -1)); // end < 0
|
||||
|
@ -48,6 +58,18 @@ void testDecodeSlice() {
|
|||
Expect.equals("\u0082\u1041", decoder.convert(utf8, 2));
|
||||
Expect.equals("\u0081\u0082", decoder.convert(utf8, 0, 4));
|
||||
Expect.equals("\u0082", decoder.convert(utf8, 2, 4));
|
||||
|
||||
if (utf8 is Uint8List) {
|
||||
Expect.equals("\u0081\u0082\u1041",
|
||||
decoder.convert(Uint8List.sublistView(utf8, 0)));
|
||||
Expect.equals(
|
||||
"\u0082\u1041", decoder.convert(Uint8List.sublistView(utf8, 2)));
|
||||
Expect.equals(
|
||||
"\u0081\u0082", decoder.convert(Uint8List.sublistView(utf8, 0, 4)));
|
||||
Expect.equals(
|
||||
"\u0082", decoder.convert(Uint8List.sublistView(utf8, 2, 4)));
|
||||
}
|
||||
|
||||
Expect.throws(() => decoder.convert(utf8, 1));
|
||||
Expect.throws(() => decoder.convert(utf8, 0, 1));
|
||||
Expect.throws(() => decoder.convert(utf8, 2, 5));
|
||||
|
|
Loading…
Reference in a new issue