Error decoding object with large buffer

Aperta
#43 12 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
43/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, node.js
Ambito
backend, data

Direzione di ricerca

The report reproduces the failure with cbor.encode and cbor.decode on an object containing a large buffer, and includes a stack trace pointing to lib/decoder.js. Start by checking the decoder path around decodeFirstSync and reproduce with the supplied snippet, varying buffer size and property order. Done means the encoded object decodes correctly across the reported cases, with a regression test covering the size and ordering behavior.

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

Descrizione

The following snippet fails with error at decode:

    let buffer = fs.readFileSync('some_large_file');
    buffer = buffer.slice(0, 16377);

    let object = {
        a: buffer,
        b: 1
    };

    let encoded = cbor.encode(object);
    let decoded = cbor.decode(encoded);
Error: Insufficient data
    at Object.decodeFirstSync (/*****/node_modules/cbor/lib/decoder.js:131:15)
    at /******/index.js:24:24
    at Object.<anonymous> (/*****/index.js:181:1)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:159:18)

The size of buffer for which the error occurs depends on the name of the object properties a and b. That is, if the names are longer then shorter buffers produce the error.

With property names a and b, the error does not occur if I reduce the size of buffer to 16376 bytes, like:

    buffer = buffer.slice(0, 16376);

The error does not occur if I switch the order of a and b in object, like:

    let object = {
        b: 1,
        a: buffer
    };

Reproduced with 2.0.0 and 3.0.0

Lingua principale
JavaScript
Stelle
379
Fork
73
Merge medio
7m
PR unite (30g)
1

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Nessun modello di pull request
  • Nessuna 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 hildjj/node-cbor

Tutte le issue di hildjj/node-cbor

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.