buffer: UTF-16LE indexOf can hang on unaligned Buffer views
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à
- Attiva
- Stack tecnologico
- cpp, javascript, node.js
- Ambito
- backend
Direzione di ricerca
Esegui prima la riproduzione fornita, quindi esamina Buffer#indexOf in src/node_buffer.cc intorno alle righe 1119-1124 e l’allineamento della ricerca a 16 bit in deps/nbytes/include/nbytes.h intorno alle righe 459-465. Traccia il modo in cui una vista con offset dispari viene passata alla ricerca e aggiungi una copertura di regressione per le viste allineate e non allineate. Il lavoro è completo quando entrambe le ricerche UTF-16LE terminano e restituiscono 0.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Version
v27.0.0-pre (b805fb5158a)
Platform
Darwin 24.6.0 arm64
Subsystem
buffer
What steps will reproduce the bug?
Buffer#indexOf() can hang when its receiver is an unaligned view. The child process timeout prevents the reproduction from hanging indefinitely.
'use strict';
const { spawnSync } = require('node:child_process');
for (const prefixLength of [0, 1]) {
const source = `
const data = Buffer.from('abc', 'utf16le');
const backing = Buffer.alloc(data.length + ${prefixLength});
data.copy(backing, ${prefixLength});
const view = backing.subarray(${prefixLength});
console.log(view.indexOf('a', 0, 'utf16le'));
`;
const result = spawnSync(process.execPath, ['-e', source], {
encoding: 'utf8',
timeout: 2000,
});
console.log({
prefixLength,
status: result.status,
error: result.error?.code,
stdout: result.stdout.trim(),
});
}
How often does it reproduce? Is there a required condition?
It's consistent when the receiver view starts at an odd byte offset. The aligned control returns normally.
What is the expected behavior? Why is that the expected behavior?
Both searches should terminate and return 0.
The views contain the same bytes, and the UTF-16LE value begins at index 0 of each view. The result should not depend on the underlying memory address.
What do you see instead?
The aligned view returns 0. The view starting at byte offset 1 does not complete before the timeout:
{ prefixLength: 0, status: 0, error: undefined, stdout: '0' }
{ prefixLength: 1, status: null, error: 'ETIMEDOUT', stdout: '' }
Additional information
Buffer#indexOf() passes the receiver data to the 16-bit search, while nbytes aligns matched addresses down. For an odd-offset view, this can move before the start of the view and appears to cause the hang.
This is distinct from #26448, which concerns search-offset rounding, and remains reproducible after #65905, which affects UTF-16LE decoding rather than Buffer#indexOf().
Copying the view or using a Buffer needle avoids the hang. Both workarounds return 0 locally:
Buffer.from(view).indexOf('a', 0, 'utf16le');
view.indexOf(Buffer.from('a', 'utf16le'));
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.4k
- Merge medio
- 4g 3h
- PR unite (30g)
- 272
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nodejs/node
-
doc
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
build
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
feature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
avniproject/avni-client#2135 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
babalae/bettergi-scripts-list#3674 ·
-
A-Release-Notes C-Editing D-Modest S-Ready-For-Implementation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
bevyengine/bevy-website#2595 ·
-
ecosystem wording
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
matrix-org/matrix.org#3649 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
vadimdemedes/ink#1029 ·