nodejs / nodejs/node

buffer.toString() fails when buffer.length >= 32 and null-terminated on big-endian

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

还没有人认领这个 Issue。

linux s390x
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

Version

v24.18.0, v26.5.0

Platform
Linux zelenka 6.12.96+deb13-s390x #1 SMP Debian 6.12.96-1 (2026-07-20) s390x GNU/Linux
Subsystem

StringBytes

What steps will reproduce the bug?

Run these commands

node -p 'const b=Buffer.alloc(32); b.write("\u3000",0,"utf8");b.toString().charCodeAt(0);'
node -p 'Buffer.from("\u3000").toString().charCodeAt(0);'
How often does it reproduce? Is there a required condition?

Always reproduced on big-endian.

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

both commands should return 12288

What do you see instead?

On big-endian architecture (e.g. s390x) the first call returns 0 and the last 12288.

Additional information

Tested with the executables provided by nodejs.org.
v22.23.1 is not affected.
Also, this gives the correct result on big-endian:

node -p 'const b=Buffer.alloc(31); b.write("\u3000",0,"utf8");b.toString().charCodeAt(0);'

So the suspected commits are the ones adding the special cases for buflen >= 32 here:
https://github.com/nodejs/node/blob/68130800586634f17812f3b0837d869a36725e98/src/string_bytes.cc#L751
and here
https://github.com/nodejs/node/blob/68130800586634f17812f3b0837d869a36725e98/src/string_bytes.cc#L625

贡献指南

打开贡献指南

从这里开始

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

调研方向

在 big-endian 系统上运行两个复现命令,并将它们与 31 字节的情况进行比较。然后检查 src/string_bytes.cc 中所引用的第 625 行和第 751 行附近的代码,重点关注对 buflen >= 32 的特殊处理。当两个命令在 big-endian 上都返回 12288,且现有的 31 字节行为没有发生回归时,即表示完成。

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

评估

技术栈
cpp, nodejs
领域
backend, operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 发到你的邮箱

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