Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: test/unittests/value-serializer-unittest.cc

Issue 2645673002: ValueSerializer: Fail decode if no memory is available when decoding ArrayBuffer. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/value-serializer-unittest.cc
diff --git a/test/unittests/value-serializer-unittest.cc b/test/unittests/value-serializer-unittest.cc
index 48ac722aa33bf4572bcefd9356495c45469364c5..f0020c53b03431bfd0f880733b3316aac74df99c 100644
--- a/test/unittests/value-serializer-unittest.cc
+++ b/test/unittests/value-serializer-unittest.cc
@@ -1744,6 +1744,38 @@ TEST_F(ValueSerializerTest, DecodeInvalidArrayBuffer) {
InvalidDecodeTest({0xff, 0x09, 0x42, 0xff, 0xff, 0x00});
}
+// An array buffer allocator that never has available memory.
+class OOMArrayBufferAllocator : public ArrayBuffer::Allocator {
+ public:
+ void* Allocate(size_t) override { return nullptr; }
+ void* AllocateUninitialized(size_t) override { return nullptr; }
+ void Free(void*, size_t) override {}
+};
+
+TEST_F(ValueSerializerTest, DecodeArrayBufferOOM) {
+ // This test uses less of the harness, because it has to customize the
+ // isolate.
+ OOMArrayBufferAllocator allocator;
+ Isolate::CreateParams params;
+ params.array_buffer_allocator = &allocator;
+ Isolate* isolate = Isolate::New(params);
+ Isolate::Scope isolate_scope(isolate);
+ HandleScope handle_scope(isolate);
+ Local<Context> context = Context::New(isolate);
+ Context::Scope context_scope(context);
+ TryCatch try_catch(isolate);
+
+ const std::vector<uint8_t> data = {0xff, 0x09, 0x3f, 0x00, 0x42,
+ 0x03, 0x00, 0x80, 0xff, 0x00};
+ ValueDeserializer deserializer(isolate, &data[0],
+ static_cast<int>(data.size()), nullptr);
+ deserializer.SetSupportsLegacyWireFormat(true);
+ ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false));
+ ASSERT_FALSE(try_catch.HasCaught());
+ EXPECT_TRUE(deserializer.ReadValue(context).IsEmpty());
+ EXPECT_TRUE(try_catch.HasCaught());
+}
+
// Includes an ArrayBuffer wrapper marked for transfer from the serialization
// context to the deserialization context.
class ValueSerializerTestWithArrayBufferTransfer : public ValueSerializerTest {
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698