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

Aperta
#64,807 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
cpp, nodejs

Direzione di ricerca

Esegui i due comandi di riproduzione su un sistema big-endian e confrontali con il caso da 31 byte. Poi esamina src/string_bytes.cc intorno alle righe indicate 625 e 751, concentrandoti sulla gestione speciale di buflen >= 32. Il lavoro è completato quando entrambi i comandi restituiscono 12288 su big-endian senza introdurre regressioni nel comportamento esistente per 31 byte.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

linux s390x
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

Lingua principale
JavaScript
Stelle
122k
Fork
37.4k
Merge medio
4g 3h
PR unite (30g)
273

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/node

Tutte le issue di nodejs/node

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.