Commit 679c317e authored by Victor Costan's avatar Victor Costan Committed by V8 LUCI CQ

Restore typed array serialization format.

https://crrev.com/c/3297708 changed the serialization format for typed
arrays without bumping the format version. As a consequence, builds that
include that CL fail to deserialize typed arrays serialized by previous
V8 versions.

This CL reverts the serialization format change, and does minimal test
changes to reflect the revert. https://crbug.com/v8/12532 tracks
serializing typed array flags in a backwards-compatible manner.

Bug: chromium:1284506
Change-Id: Ib32e88c6383e0ad4ad1a9ff63f413a1eb123b1ef
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3370408Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78507}
parent 86aa8e40
......@@ -938,7 +938,11 @@ Maybe<bool> ValueSerializer::WriteJSArrayBufferView(JSArrayBufferView view) {
WriteVarint(static_cast<uint8_t>(tag));
WriteVarint(static_cast<uint32_t>(view.byte_offset()));
WriteVarint(static_cast<uint32_t>(view.byte_length()));
WriteVarint(static_cast<uint32_t>(view.bit_field()));
// TODO(crbug.com/v8/12532): Re-enable the flags serialization logic below.
// Bump the serialization format version number when doing so, and preserve
// logic and tests for reading from the old format.
//
// WriteVarint(static_cast<uint32_t>(view.bit_field()));
return ThrowIfOutOfMemory();
}
......@@ -1864,10 +1868,12 @@ MaybeHandle<JSArrayBufferView> ValueDeserializer::ReadJSArrayBufferView(
uint32_t byte_offset = 0;
uint32_t byte_length = 0;
uint32_t flags = 0;
// TODO(crbug.com/v8/12532): Read `flags` from the serialized value, when we
// restore the logic for serializing them.
if (!ReadVarint<uint8_t>().To(&tag) ||
!ReadVarint<uint32_t>().To(&byte_offset) ||
!ReadVarint<uint32_t>().To(&byte_length) ||
!ReadVarint<uint32_t>().To(&flags) || byte_offset > buffer_byte_length ||
byte_offset > buffer_byte_length ||
byte_length > buffer_byte_length - byte_offset) {
return MaybeHandle<JSArrayBufferView>();
}
......
......@@ -1860,16 +1860,15 @@ TEST_F(ValueSerializerTest, RoundTripTypedArray) {
TEST_F(ValueSerializerTest, DecodeTypedArray) {
// Check that the right type comes out the other side for every kind of typed
// array.
Local<Value> value =
DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x02, 0x00, 0x00,
0x56, 0x42, 0x00, 0x02, 0x00});
Local<Value> value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42,
0x02, 0x00, 0x00, 0x56, 0x42, 0x00, 0x02});
ASSERT_TRUE(value->IsUint8Array());
EXPECT_EQ(2u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
ExpectScriptTrue("Object.getPrototypeOf(result) === Uint8Array.prototype");
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x02, 0x00,
0x00, 0x56, 0x62, 0x00, 0x02, 0x00});
0x00, 0x56, 0x62, 0x00, 0x02});
ASSERT_TRUE(value->IsInt8Array());
EXPECT_EQ(2u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
......@@ -1877,38 +1876,38 @@ TEST_F(ValueSerializerTest, DecodeTypedArray) {
#if defined(V8_TARGET_LITTLE_ENDIAN)
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x04, 0x00,
0x00, 0x00, 0x00, 0x56, 0x57, 0x00, 0x04, 0x00});
0x00, 0x00, 0x00, 0x56, 0x57, 0x00, 0x04});
ASSERT_TRUE(value->IsUint16Array());
EXPECT_EQ(4u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
ExpectScriptTrue("Object.getPrototypeOf(result) === Uint16Array.prototype");
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x04, 0x00,
0x00, 0x00, 0x00, 0x56, 0x77, 0x00, 0x04, 0x00});
0x00, 0x00, 0x00, 0x56, 0x77, 0x00, 0x04});
ASSERT_TRUE(value->IsInt16Array());
EXPECT_EQ(4u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
ExpectScriptTrue("Object.getPrototypeOf(result) === Int16Array.prototype");
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x56, 0x44, 0x00, 0x08, 0x00});
value =
DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x44, 0x00, 0x08});
ASSERT_TRUE(value->IsUint32Array());
EXPECT_EQ(8u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
ExpectScriptTrue("Object.getPrototypeOf(result) === Uint32Array.prototype");
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x56, 0x64, 0x00, 0x08, 0x00});
value =
DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x64, 0x00, 0x08});
ASSERT_TRUE(value->IsInt32Array());
EXPECT_EQ(8u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
ExpectScriptTrue("Object.getPrototypeOf(result) === Int32Array.prototype");
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x56, 0x66, 0x00, 0x08, 0x00});
value =
DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x66, 0x00, 0x08});
ASSERT_TRUE(value->IsFloat32Array());
EXPECT_EQ(8u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
......@@ -1917,7 +1916,7 @@ TEST_F(ValueSerializerTest, DecodeTypedArray) {
value =
DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x56, 0x46, 0x00, 0x10, 0x00});
0x00, 0x00, 0x00, 0x00, 0x56, 0x46, 0x00, 0x10});
ASSERT_TRUE(value->IsFloat64Array());
EXPECT_EQ(16u, TypedArray::Cast(*value)->ByteLength());
EXPECT_EQ(2u, TypedArray::Cast(*value)->Length());
......@@ -1927,19 +1926,18 @@ TEST_F(ValueSerializerTest, DecodeTypedArray) {
// Check that values of various kinds are suitably preserved.
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x03, 0x01,
0x80, 0xFF, 0x56, 0x42, 0x00, 0x03, 0x00});
0x80, 0xFF, 0x56, 0x42, 0x00, 0x03});
ExpectScriptTrue("result.toString() === '1,128,255'");
#if defined(V8_TARGET_LITTLE_ENDIAN)
value =
DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x06, 0x00, 0x00,
0x00, 0x01, 0x00, 0x80, 0x56, 0x77, 0x00, 0x06, 0x00});
value = DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x06, 0x00,
0x00, 0x00, 0x01, 0x00, 0x80, 0x56, 0x77, 0x00, 0x06});
ExpectScriptTrue("result.toString() === '0,256,-32768'");
value =
DecodeTest({0xFF, 0x09, 0x3F, 0x00, 0x3F, 0x00, 0x42, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0xC0, 0x7F,
0x00, 0x00, 0x80, 0x7F, 0x56, 0x66, 0x00, 0x10, 0x00});
0x00, 0x00, 0x80, 0x7F, 0x56, 0x66, 0x00, 0x10});
ExpectScriptTrue("result.toString() === '0,-0.5,NaN,Infinity'");
#endif // V8_TARGET_LITTLE_ENDIAN
......@@ -1954,7 +1952,7 @@ TEST_F(ValueSerializerTest, DecodeTypedArray) {
0x00, 0x56, 0x42, 0x00, 0x20, 0x00, 0x3F, 0x03, 0x53, 0x04, 0x75, 0x38,
0x5F, 0x32, 0x3F, 0x03, 0x5E, 0x02, 0x3F, 0x03, 0x53, 0x03, 0x66, 0x33,
0x32, 0x3F, 0x03, 0x3F, 0x03, 0x5E, 0x01, 0x56, 0x66, 0x04, 0x14, 0x00,
0x3F, 0x04, 0x53, 0x01, 0x62, 0x3F, 0x04, 0x5E, 0x01, 0x7B, 0x04, 0x00});
0x3F, 0x04, 0x53, 0x01, 0x62, 0x3F, 0x04, 0x5E, 0x01, 0x7B, 0x04});
ExpectScriptTrue("result.u8 instanceof Uint8Array");
ExpectScriptTrue("result.u8 === result.u8_2");
ExpectScriptTrue("result.f32 instanceof Float32Array");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment