nodejs / nodejs/node

wasm: streaming APIs accept non-Uint8Array response body chunks

未关闭
#64,669 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

Version

latest main branch

Platform
7.1.3-arch1-3
Subsystem

wasm

What steps will reproduce the bug?
const bytes = new Uint8Array([
  0x00, 0x61, 0x73, 0x6d, // \0asm
  0x01, 0x00, 0x00, 0x00, // version 1
]);

const stream = new ReadableStream({
  start(controller) {
    controller.enqueue(bytes.buffer); // ArrayBuffer, not Uint8Array
    controller.close();
  },
});

const response = new Response(stream, {
  headers: {
    'Content-Type': 'application/wasm',
  },
});

WebAssembly.compileStreaming(response).then(
  () => console.log('unexpectedly compiled'),
  (error) => console.error('rejected:', error),
);
How often does it reproduce? Is there a required condition?

Every

What is the expected behavior? Why is that the expected behavior?

Fetch body consumption requires every chunk read from the response body to be a Uint8Array. Other values, including ArrayBuffer, DataView, and other typed arrays, should cause the operation to reject with a TypeError.

What do you see instead?

WebAssembly.compileStreaming() and WebAssembly.instantiateStreaming() accept response bodies whose
ReadableStream produces non-Uint8Array chunks.The WebAssembly module is compiled successfully, even though the response body produces an ArrayBuffer chunk.

Additional information

Refs: https://github.com/web-platform-tests/wpt/blob/master/wasm/webapi/wasm_stream_compile_test.any.js#L80-L93
Refs: https://github.com/web-platform-tests/wpt/blob/master/wasm/webapi/wasm_stream_instantiate_test.any.js#L79-L92

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 WebAssembly.compileStreaming() 和 WebAssembly.instantiateStreaming() 入口点,以及所引用的 WPT 测试 wasm/webapi/wasm_stream_compile_test.any.js 和 wasm/webapi/wasm_stream_instantiate_test.any.js 开始。复现报告中的 ArrayBuffer 分块情况,然后验证非 Uint8Array 的响应分块会因 TypeError 被拒绝,而有效分块仍能正常工作。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, wasm
领域
api
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
65/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。