`Buffer.concat` and `Buffer.copy` silently produce invalid results when the operation involves indices equal or greater than 2^32
未关闭
还没有人认领这个 Issue。
buffer
confirmed-bug
help wanted
regression
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
Version
v22.9.0, v23.0.0
Platform
Windows 11 x64
Microsoft Windows NT 10.0.22631.0 x64
Subsystem
Buffer
What steps will reproduce the bug?
const largeBuffer = Buffer.alloc(2 ** 32 + 5)
largeBuffer.fill(111)
const result = Buffer.concat([largeBuffer])
console.log(result)
How often does it reproduce? Is there a required condition?
Consistent in v22.9.0 and v23.0.0
What is the expected behavior? Why is that the expected behavior?
All bytes of the return buffer produced by Buffer.concat([largeBuffer]) should be identical to the source:
In this example:
111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, ....
What do you see instead?
In the returned buffer, first 5 bytes are 111, and all following ones are 0.
111, 111, 111, 111, 111, 0, 0, 0, 0, 0, 0, ....
The console.log(result) output looks like:
<Buffer 6f 6f 6f 6f 6f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 4294967251
more bytes>
Additional information
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 Windows x64 上运行使用 Node.js v22.9.0 或 v23.0.0 的已报告复现,然后检查 Buffer.concat 和 Buffer.copy 的实现及其现有测试。跟踪大于或等于 2^32 的索引处理。完成的标准是大型缓冲区操作保留所有源字节,并且回归测试覆盖并验证该边界行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100