Decoder accepts non-minimal integer encodings
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 73/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- javascript, node.js
Línea de trabajo
Empieza por rastrear la ruta de decodificación de argumentos enteros que utiliza decodeFirstSync y, después, lee las pruebas existentes del decodificador para las codificaciones de enteros. Añade un caso para los bytes no mínimos proporcionados y verifica que la decodificación los rechaza, mientras que el 17 canónico sigue completando el viaje de ida y vuelta. El issue no indica archivos fuente ni de pruebas, así que localiza primero esos puntos de entrada en el repositorio.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- JavaScript
- Estrellas
- 379
- Forks
- 73
- Merge medio
- 7 min
- PR fusionados (30 d)
- 1
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de hildjj/node-cbor
-
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
-
Print embedded CBOR in cbor2diagAbiertoenhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 36/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
Todos los issues de hildjj/node-cbor
Issues similares
-
Out of order / duplicate key error shows the key bytes as decimal or UTF-8, not hexPosiblemente ocupada @bardrop la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
Los mantenedores suelen responder en 3 días
-
`remix-hook-form/middleware` imports `unstable_createContext`, breaking on `react-router` >= 7.9.0Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
code-forge-io/remix-hook-form#189 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100