buffer.toString() fails when buffer.length >= 32 and null-terminated on big-endian
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
big-endian システムで 2 つの再現コマンドを実行し、31 バイトの場合と比較します。次に、参照されている 625 行目と 751 行目付近の src/string_bytes.cc を調べ、buflen >= 32 の特殊な処理に注目します。big-endian で両方のコマンドが 12288 を返し、既存の 31 バイトの動作を退行させなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- cpp, nodejs
- 領域
- backend, operating-systems
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 68/100