BooleanType.serialize accepts non-boolean values via truthiness
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- backend
調査の方向性
バグは BooleanType の value_serializeToBytes メソッドにあり、真偽値の判定(value ? 1 : 0)を使っています。すでに fromJson と deserialize のパスにある厳密なチェックと比較し、issue に記載された型の強制変換のケースを短いスクリプトまたはテストで再現してください。真偽値以外の値に対して serialize が分かりやすい型エラーを投げ、true と false が引き続き 0x01 と 0x00 にエンコードされれば完了です。boolean 型のテストがすべて通ることも確認してください。
索引モデルが 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分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ChainSafe/ssz のほかの issue
-
ListBasicType.serialize accepts values longer than the list limit対応中かも @kutluhaneth46 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ChainSafe/ssz#575 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
BitList deserialization with reuseBytes: true mutates the input buffer対応中かも @yinbowen-dc が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
ChainSafe/ssz#559 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bitlist maxSize off by one and inconsistent progressive list default limits対応中かも @yinbowen-dc が 10 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ChainSafe/ssz#548 · コメント 1 件 ·
メンテナーはふだん 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 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
compiler-explorer/compiler-explorer#9710 ·
メンテナーはふだん 1 日以内に返信
-
test(web): RevealArtwork's warm tests flake on CI because a 0 ms idle timeout means no deadlineオープン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 日以内に返信