Decoder accepts non-minimal integer encodings
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 73/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- javascript, node.js
调研方向
先追踪 decodeFirstSync 使用的整数参数解码路径,然后阅读现有的整数编码解码器测试。为给定的非最小字节添加一个用例,并验证解码会拒绝这些字节,同时规范形式的 17 仍可往返。issue 未指出源文件或测试文件,因此先在仓库中定位这些入口。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- JavaScript
- 星标
- 380
- 派生
- 73
- 平均合并
- 7 分钟
- 30 天内合并 PR
- 1
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
hildjj/node-cbor 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 58/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
相似的 Issue
-
enhancement ready
难度 2/5 1-3 小时 新手友好度 84/100
-
enhancement
难度 2/5 1-3 小时 新手友好度 75/100
DCGM/semant-demo#708 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 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
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Client codegen: an import repeated in an impl file is emitted twice, and the browser rejects the module可能已有人在做 @MalithaPrabhashana 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 64/100
jaseci-labs/jac#10756 ·
维护者通常 1 天内回复