aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-06-05 17:17:35 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-06-05 17:17:48 -0700
commit0c11762c310c2655fe5c3ecc60671c93934abdc3 (patch)
tree6fc2b4bbf658ee5fd2d5c62933f6f1ff411d026a
parentfe7d5357d8b025c671944705047338c1aa26be4a (diff)
downloadbun-0c11762c310c2655fe5c3ecc60671c93934abdc3.tar.gz
bun-0c11762c310c2655fe5c3ecc60671c93934abdc3.tar.zst
bun-0c11762c310c2655fe5c3ecc60671c93934abdc3.zip
[node:vm] Fix crash when `new ArrayBuffer()` is returned
-rw-r--r--src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp4
-rw-r--r--test/js/node/vm/vm.test.ts21
2 files changed, 25 insertions, 0 deletions
diff --git a/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp b/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp
index 4c9660e26..ca8c79aef 100644
--- a/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp
+++ b/src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp
@@ -51,6 +51,10 @@ JSC::JSArrayBuffer* WebCoreTypedArrayController::toJS(JSC::JSGlobalObject* lexic
void WebCoreTypedArrayController::registerWrapper(JSC::JSGlobalObject* globalObject, JSC::ArrayBuffer* native, JSC::JSArrayBuffer* wrapper)
{
+ // require("vm") can be used to create an ArrayBuffer
+ if (UNLIKELY(!globalObject->inherits<JSDOMGlobalObject>()))
+ return;
+
cacheWrapper(JSC::jsCast<JSDOMGlobalObject*>(globalObject)->world(), native, wrapper);
}
diff --git a/test/js/node/vm/vm.test.ts b/test/js/node/vm/vm.test.ts
index 1aba597c7..510448c5e 100644
--- a/test/js/node/vm/vm.test.ts
+++ b/test/js/node/vm/vm.test.ts
@@ -74,6 +74,27 @@ function testRunInContext(
const result = fn("1 + 1; 2 * 2; 3 / 3", context);
expect(result).toBe(1);
});
+
+ for (let View of [
+ ArrayBuffer,
+ SharedArrayBuffer,
+ Uint8Array,
+ Int8Array,
+ Uint16Array,
+ Int16Array,
+ Uint32Array,
+ Int32Array,
+ Float32Array,
+ Float64Array,
+ BigInt64Array,
+ BigUint64Array,
+ ]) {
+ test(`new ${View.name}() in VM context doesn't crash`, () => {
+ const context = createContext({});
+ expect(fn(`new ${View.name}(2)`, context)).toHaveLength(2);
+ });
+ }
+
test("can return a function", () => {
const context = createContext({});
const result = fn("() => 'bar';", context);