Decoder accepts indefinite-length items
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 58/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- javascript, node.js
調査の方向性
Start by tracing the decoder path used by decodeFirstSync and how it handles indefinite-length items; compare that behavior with the encoder’s output and the CBOR specification linked in the issue. Add coverage for the supplied byte sequence and verify that decoding rejects it in strict or canonical mode, while checking existing tests for any intended lenient behavior.
索引モデルが issue の本文から書いたものです。
説明
Summary
RFC 8949 section 4.2.1 forbids indefinite-length items in the deterministic encoding profile, and DAG-CBOR forbids them outright, because the same value then has more than one valid encoding.
Specification: https://ipld.io/specs/codecs/dag-cbor/spec/
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('bf617007617007ff', '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 : bf617007617007ff
decoded : {"p":7}
re-encode: a1617007
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 07, which round-trips byte-identically.
Suggested fix
Reject the indefinite-length initial byte outright when decoding, rather than
assembling the chunks into a definite-length value. A strict/canonical decode
mode is the usual place for this if the lenient behaviour must stay available.
- 主要言語
- JavaScript
- スター
- 379
- フォーク
- 73
- 平均マージ
- 7分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
hildjj/node-cbor のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 36/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
hildjj/node-cbor の issue をすべて見る
似ている issue
-
Out of order / duplicate key error shows the key bytes as decimal or UTF-8, not hex対応中かも @bardrop が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
メンテナーはふだん 3 日以内に返信
-
`remix-hook-form/middleware` imports `unstable_createContext`, breaking on `react-router` >= 7.9.0オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
code-forge-io/remix-hook-form#189 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100