[api] Relax CHECK for ArrayBuffer API abuse
authoradamk <adamk@chromium.org>
Wed, 19 Aug 2015 21:53:01 +0000 (14:53 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 19 Aug 2015 21:53:17 +0000 (21:53 +0000)
Zero-length ArrayBuffers are allowed to have NULL backing stores.

BUG=522496
LOG=n

Review URL: https://codereview.chromium.org/1302803003

Cr-Commit-Position: refs/heads/master@{#30259}

src/api.cc
test/mjsunit/regress/regress-crbug-522496.js [new file with mode: 0644]

index b46d69f..7720147 100644 (file)
@@ -6560,7 +6560,7 @@ Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
                                         size_t byte_length,
                                         ArrayBufferCreationMode mode) {
   // Embedders must guarantee that the external backing store is valid.
-  CHECK(data != NULL);
+  CHECK(byte_length == 0 || data != NULL);
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
   LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
   ENTER_V8(i_isolate);
@@ -6759,7 +6759,7 @@ Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
     ArrayBufferCreationMode mode) {
   CHECK(i::FLAG_harmony_sharedarraybuffer);
   // Embedders must guarantee that the external backing store is valid.
-  CHECK(data != NULL);
+  CHECK(byte_length == 0 || data != NULL);
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
   LOG_API(i_isolate, "v8::SharedArrayBuffer::New(void*, size_t)");
   ENTER_V8(i_isolate);
diff --git a/test/mjsunit/regress/regress-crbug-522496.js b/test/mjsunit/regress/regress-crbug-522496.js
new file mode 100644 (file)
index 0000000..e47e0a0
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+if (this.Worker) {
+  var worker = new Worker("onmessage = function(){}");
+  var buf = new ArrayBuffer();
+  worker.postMessage(buf, [buf]);
+}