Decoder accepts non-minimal integer encodings
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 73/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, node.js
Direzione di ricerca
Inizia tracciando il percorso di decodifica degli argomenti interi usato da decodeFirstSync, poi leggi i test esistenti del decoder per le codifiche degli interi. Aggiungi un caso per i byte non minimali forniti e verifica che la decodifica li rifiuti, mentre il 17 canonico continua a completare il round trip. L’issue non indica file sorgente o di test, quindi individua prima questi punti di ingresso nel repository.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
RFC 8949 section 4.2.1 requires the shortest form of an argument that holds the value: a value expressible in the immediate additional-information field must not be written with a wider argument. DAG-CBOR strengthens this to a single canonical encoding per value.
Specification: https://www.rfc-editor.org/rfc/rfc8949#section-4.2.1
Problem
node-cbor accepts an input that its own encoder would
never produce. Decoding the witness below succeeds, and re-encoding the
decoded value with the same library yields different bytes. The library is
therefore not the inverse of itself on this input, so two peers that disagree
about whether to accept it will disagree about the value's encoding, and any
system that treats the encoding as identifying (content addressing, signature
preimages, deduplication) can be made to see two encodings of one value.
Version tested: cbor 10.0.12
Reproduction
import cbor from 'cbor';
const buf = Buffer.from('1a0000000f', 'hex');
const v = cbor.decodeFirstSync(buf);
const re = Buffer.from(cbor.encodeOne(v));
console.log('input :', buf.toString('hex'));
console.log('decoded :', JSON.stringify(v, (_k, x) => typeof x === 'bigint' ? x.toString() : x));
console.log('re-encode:', re.toString('hex'));
console.log(re.equals(buf) ? 'ROUNDTRIP-STABLE' : 'REENCODE-DIFFERS');
Observed output:
input : 1a0000000f
decoded : 15
re-encode: 0f
REENCODE-DIFFERS
The re-encoding differs from the input, which is the defect.
Expected behavior
The decoder should reject this input rather than accept it, because the
encoding is not the canonical one for the decoded value. A canonical encoding of the same value is 17, which round-trips byte-identically.
Suggested fix
While decoding an integer argument, check that the value could not have been
written in a shorter form, and reject it if it could. Normalising at encode
time does not help: by then the non-canonical bytes have already been accepted.
- Lingua principale
- JavaScript
- Stelle
- 379
- Fork
- 73
- Merge medio
- 7m
- PR unite (30g)
- 1
Preparare l'ambiente
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
- 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 hildjj/node-cbor
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 36/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
Tutte le issue di hildjj/node-cbor
Issue simili
-
enhancement ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
DCGM/semant-demo#708 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
agents area: runtime automation chore cli consistency dependencies developer-experience difficulty: easy documentation enhancement good first issue help wanted hygiene json-output priority: P3 starters tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Client codegen: an import repeated in an impl file is emitted twice, and the browser rejects the moduleForse già presa @MalithaPrabhashana l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
jaseci-labs/jac#10756 ·
I maintainer di solito rispondono entro 1 giorno