Skip to content

Truly independent web browser

LibWeb: Throw a DataCloneError for a record that names a missing object

Shannon Boothb158b4dbac89
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
index 4be454bfa63..1e669e24e3d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
@@ -959,6 +959,12 @@ impl Deserializer<'_, '_> {
if index == u32::MAX {
return Ok(Value::from_object(Object::create(vm, realm, None)));
}
+ if index as usize >= self.memory.size() {
+ return Err(data_clone_error_from_serialization_error(
+ realm,
+ "ObjectReference index out of range",
+ ));
+ }
return Ok(self.memory.get(index as usize));
}
diff --git a/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp b/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
index 7e162bbe39c..c8ea9ee448e 100644
--- a/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
+++ b/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
@@ -612,7 +612,7 @@ bool web_structured_serialize_is_transferable_interface_exposed(u8 type, void* r
dbgln("Unknown interface type for transfer: {}", to_underlying(name));
break;
default:
- VERIFY_NOT_REACHED();
+ break;
}
return false;
}
diff --git a/Tests/LibWeb/TestStructuredSerializeHardening.cpp b/Tests/LibWeb/TestStructuredSerializeHardening.cpp
index e935e62eeb8..2ac9f5f2537 100644
--- a/Tests/LibWeb/TestStructuredSerializeHardening.cpp
+++ b/Tests/LibWeb/TestStructuredSerializeHardening.cpp
@@ -172,6 +172,23 @@ TEST_CASE(storage_reader_rejects_invalid_value_tags)
EXPECT(storage_deserialize(with_tag(99)).is_error()); // Beyond the last defined tag.
}
+TEST_CASE(storage_reader_rejects_an_object_reference_past_the_memory)
+{
+ // Nothing has been deserialized yet, so there is no object for index 0 to name.
+ Vector<u8> value { to_underlying(ValueTag::ObjectReference) };
+ append_storage_leb128(value, 0);
+ EXPECT(storage_deserialize(storage_record_with_value(value)).is_error());
+}
+
+TEST_CASE(transfer_receiver_rejects_an_unknown_transfer_type)
+{
+ auto& realm = test_realm();
+ Web::HTML::TransferDataEncoder holder;
+ MUST(holder.encode(static_cast<u8>(0xEE)));
+ Web::HTML::TransferDataDecoder decoder { move(holder) };
+ EXPECT(Web::HTML::structured_deserialize_with_transfer_internal(decoder, realm).is_error());
+}
+
TEST_CASE(storage_reader_rejects_a_truncated_or_overlong_int32)
{
auto int32_record = [](Vector<u8> const& body) {