BooleanType.serialize accepts non-boolean values via truthiness
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- backend
调研方向
问题出在 BooleanType 的 value_serializeToBytes 方法中,它使用了真值判断(value ? 1 : 0)。请将其与 fromJson 和 deserialize 路径中已有的严格检查进行对比,并用一个简短的脚本或测试复现 issue 中的强制转换情况。完成的标准是:serialize 对非布尔值抛出清晰的类型错误,同时 true 和 false 仍分别编码为 0x01 和 0x00。另外请确认布尔类型的测试仍然全部通过。
由索引模型根据 Issue 内容生成。
描述
Description
BooleanType.fromJson and BooleanType.deserialize both require a real boolean (true/false, or byte 0x00/0x01). BooleanType.serialize does not: it uses a truthy check (value ? 1 : 0), so numbers, strings, null, and undefined are silently encoded as 0x00 or 0x01.
That makes the encode path accept values the JSON and decode paths reject, and it can hide type mistakes in client code.
Related but separate from #574 / PR #574 (packed tree deserialize accepting byte values other than 0/1). This report is about the value serialize API coercing non-booleans.
Version
@chainsafe/ssz 1.9.1 (also reproduced on current packages/ssz master)
Repro
import { BooleanType } from "@chainsafe/ssz";
const b = new BooleanType();
b.serialize(true); // Uint8Array [1]
b.serialize(false); // Uint8Array [0]
// Non-booleans are accepted and coerced:
b.serialize(2 as any); // Uint8Array [1]
b.serialize("x" as any); // Uint8Array [1]
b.serialize(0 as any); // Uint8Array [0]
b.serialize("" as any); // Uint8Array [0]
b.serialize(null as any); // Uint8Array [0]
b.serialize(undefined as any); // Uint8Array [0]
// Contrast: fromJson / deserialize are strict
b.fromJson(1); // throws: JSON invalid type number expected boolean
b.deserialize(Uint8Array.of(2)); // throws: Boolean: invalid value: 2
Cause is here:
value_serializeToBytes(output, offset, value) {
output.uint8Array[offset] = value ? 1 : 0;
return offset + 1;
}
Expected
serialize should reject non-boolean values the same way fromJson does (throw a clear type error), so only true/false encode to 0x01/0x00.
Actual
Any truthy value encodes as 0x01 and any falsy value as 0x00, with no error.
- 主要语言
- TypeScript
- 星标
- 62
- 派生
- 30
- 平均合并
- 4 小时 37 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ChainSafe/ssz 的其他 Issue
-
ListBasicType.serialize accepts values longer than the list limit可能已有人在做 @kutluhaneth46 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
BitList deserialization with reuseBytes: true mutates the input buffer可能已有人在做 @yinbowen-dc 于 9 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bitlist maxSize off by one and inconsistent progressive list default limits可能已有人在做 @yinbowen-dc 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
SSZ Union Deserialization Vulnerable to Trailing Data for Certain Variants可能已有人在做 @shadowzzed 于 80 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
UintNumberType.serialize silently wraps out-of-range values (negative, NaN, overflow)可能已有人在做 @kutluhaneth46 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
相似的 Issue
-
Release utils decode git output chunk by chunk, so a multi-byte character can turn into U+FFFD可能已有人在做 @goranai 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 2 天内回复
-
Task retarget keeps the old host in task scope and adds the new host in a form that matches nothing可能已有人在做 @chaitanya0305 今天认领。 未关闭bug P2
难度 2/5 1-3 小时 新手友好度 62/100
BaaRai/ARTEX#652 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
compiler-explorer/compiler-explorer#9710 ·
维护者通常 1 天内回复
-
bug effort:S P3
难度 2/5 1-3 小时 新手友好度 72/100
nightscout/nocturne#4556 ·
维护者通常 1 天内回复
-
sumHorizontal, maxHorizontal, minHorizontal, allHorizontal, anyHorizontal, struct and argSortBy treat strings as literals instead of column names可能已有人在做 @tomaionescu 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
pola-rs/nodejs-polars#486 ·
维护者通常 1 天内回复