From 6d7964a8f4739a28c684bf58e1385a93244e072f Mon Sep 17 00:00:00 2001 From: Archkon <180910180+Archkon@users.noreply.github.com> Date: Wed, 22 Jul 2026 14:34:59 +0800 Subject: [PATCH 1/2] wasm: reject non-Uint8Array streaming chunks Restrict WebAssembly streaming response chunks to Uint8Array, as required by Fetch body consumption. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> --- src/node_wasm_web_api.cc | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/node_wasm_web_api.cc b/src/node_wasm_web_api.cc index a1e52726f3a7d0..a49fc97e87cd05 100644 --- a/src/node_wasm_web_api.cc +++ b/src/node_wasm_web_api.cc @@ -7,8 +7,6 @@ namespace node { namespace wasm_web_api { -using v8::ArrayBuffer; -using v8::ArrayBufferView; using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; @@ -17,6 +15,7 @@ using v8::Isolate; using v8::Local; using v8::MaybeLocal; using v8::Object; +using v8::Uint8Array; using v8::Value; using v8::WasmStreaming; @@ -98,28 +97,16 @@ void WasmStreamingObject::Push(const FunctionCallbackInfo& args) { CHECK_EQ(args.Length(), 1); Local chunk = args[0]; - // The start of the memory section backing the ArrayBuffer(View), the offset - // of the ArrayBuffer(View) within the memory section, and its size in bytes. - const void* bytes; - size_t offset; - size_t size; - - if (chunk->IsArrayBufferView()) [[likely]] { - Local view = chunk.As(); - bytes = view->Buffer()->Data(); - offset = view->ByteOffset(); - size = view->ByteLength(); - } else if (chunk->IsArrayBuffer()) [[likely]] { - Local buffer = chunk.As(); - bytes = buffer->Data(); - offset = 0; - size = buffer->ByteLength(); - } else { - return node::THROW_ERR_INVALID_ARG_TYPE( - Environment::GetCurrent(args), - "chunk must be an ArrayBufferView or an ArrayBuffer"); + if (!chunk->IsUint8Array()) [[unlikely]] { + return node::THROW_ERR_INVALID_ARG_TYPE(Environment::GetCurrent(args), + "chunk must be a Uint8Array"); } + Local view = chunk.As(); + const void* bytes = view->Buffer()->Data(); + size_t offset = view->ByteOffset(); + size_t size = view->ByteLength(); + // Forward the data to V8. Internally, V8 will make a copy. obj->streaming_->OnBytesReceived(static_cast(bytes) + offset, size); From 76c54358c8f130e12ae76c03688dc24bfdb3a190 Mon Sep 17 00:00:00 2001 From: Archkon <180910180+Archkon@users.noreply.github.com> Date: Wed, 22 Jul 2026 15:49:30 +0800 Subject: [PATCH 2/2]