BooleanType.serialize accepts non-boolean values via truthiness
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend
Hướng nghiên cứu
Lỗi nằm ở phương thức value_serializeToBytes của BooleanType, phương thức này dùng phép kiểm tra truthy (value ? 1 : 0). Hãy so sánh nó với các kiểm tra nghiêm ngặt đã có trong luồng fromJson và deserialize, rồi tái hiện các trường hợp ép kiểu trong issue bằng một script ngắn hoặc một bài test. Hoàn thành khi serialize ném ra lỗi kiểu rõ ràng với giá trị không phải boolean, trong khi true và false vẫn được mã hóa thành 0x01 và 0x00. Kiểm tra rằng các bài test của kiểu boolean vẫn pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 62
- Fork
- 30
- Merge trung bình
- 4 giờ 37 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ChainSafe/ssz
-
ListBasicType.serialize accepts values longer than the list limitCó thể đã có người làm @kutluhaneth46 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ChainSafe/ssz#575 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BitList deserialization with reuseBytes: true mutates the input bufferCó thể đã có người làm @yinbowen-dc đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
ChainSafe/ssz#559 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bitlist maxSize off by one and inconsistent progressive list default limitsCó thể đã có người làm @yinbowen-dc đã nhận 10 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ChainSafe/ssz#548 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SSZ Union Deserialization Vulnerable to Trailing Data for Certain VariantsCó thể đã có người làm @shadowzzed đã nhận 80 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
UintNumberType.serialize silently wraps out-of-range values (negative, NaN, overflow)Có thể đã có người làm @kutluhaneth46 đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ChainSafe/ssz
Issue tương tự
-
Release utils decode git output chunk by chunk, so a multi-byte character can turn into U+FFFDCó thể đã có người làm @goranai đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Task retarget keeps the old host in task scope and adds the new host in a form that matches nothingCó thể đã có người làm @chaitanya0305 đã nhận hôm nay. Đang mởbug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
BaaRai/ARTEX#652 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
compiler-explorer/compiler-explorer#9710 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
test(web): RevealArtwork's warm tests flake on CI because a 0 ms idle timeout means no deadlineĐang mởbug effort:S P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nightscout/nocturne#4556 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
sumHorizontal, maxHorizontal, minHorizontal, allHorizontal, anyHorizontal, struct and argSortBy treat strings as literals instead of column namesCó thể đã có người làm @tomaionescu đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pola-rs/nodejs-polars#486 ·
Maintainer thường phản hồi trong vòng 1 ngày