Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

ArrayBuffer.prototype.resize does not apply ToIndex to its argument

Aperta
#1,761 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, javascript
Ambito
backend, compilers

Direzione di ricerca

Start by locating the shared implementation of ArrayBuffer.prototype.resize and SharedArrayBuffer.prototype.grow in QuickJS-ng; the issue does not name source files or tests. Compare argument conversion and validation order with the specified ToIndex behavior, then run or add cases for Infinity, values above 2^53−1, and a throwing valueOf. Done means these cases throw the expected errors without changing buffer length.

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

Descrizione

Reproduction
const b = new ArrayBuffer(8, { maxByteLength: 16 });
b.resize(Infinity);
print(b.byteLength);
Expected

A RangeError is thrown and the buffer keeps its length.

V8 (15.6.20):

$ v8 -e 'const b = new ArrayBuffer(8, { maxByteLength: 16 }); b.resize(Infinity); print(b.byteLength);'
RangeError: ArrayBuffer.prototype.resize: Invalid length parameter
Actual (QuickJS-ng)

QuickJS-ng resizes the buffer to 0:

$ qjs -e 'const b = new ArrayBuffer(8, { maxByteLength: 16 }); b.resize(Infinity); print(b.byteLength);'
0
Spec

ArrayBuffer.prototype.resize converts its argument with ToIndex, which throws a RangeError for +∞ and for any integer above 2^53 - 1.

QuickJS-ng instead converts it modulo 2^64, so large values wrap into range rather than being rejected:

$ qjs -e 'const b = new ArrayBuffer(8, { maxByteLength: 8192 }); b.resize(2 ** 64 + 4096); print(b.byteLength);'
4096      # V8: RangeError

The same method also converts the argument too early. Its first step, RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]), throws a TypeError for a buffer that is not resizable, before ToIndex runs:

$ qjs -e 'new ArrayBuffer(8).resize({ valueOf() { throw 0; } });'
0         # V8: TypeError: Method ArrayBuffer.prototype.resize called on incompatible receiver #<ArrayBuffer>

SharedArrayBuffer.prototype.grow shares the implementation and shows both symptoms: grow(2 ** 64 + 4096) on a buffer with maxByteLength: 8192 grows it to 4096, and new SharedArrayBuffer(8).grow({ valueOf() { throw 0; } }) throws 0. Negative values are handled correctly (resize(-1) is a RangeError). This is separate from #1729, which is about the error type of transfer.

JavaScriptCore, SpiderMonkey, GraalJS and V8 all throw a RangeError for resize(Infinity).

Versions
  • QuickJS-ng: 0.17.0
  • V8: 15.6.20
Lingua principale
C
Stelle
3.9k
Fork
389
Merge medio
4g 1h
PR unite (30g)
24

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 quickjs-ng/quickjs

Tutte le issue di quickjs-ng/quickjs

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.