IntersectMBO / IntersectMBO/evolution-sdk
CBOR: bound declared array/map length against remaining bytes
- Ngôn ngữ chính
- TypeScript
- Star
- 22
- Fork
- 30
- Merge trung bình
- 5 giờ 29 phút
- Pull request đã merge (30 ngày)
- 12
Mô tả
## Summary
The definite length array and map decoders allocate and loop on the declared element count without checking it against the bytes that remain. A tiny input with a huge declared count and no element data drives a multi gigabyte fill, because reads past the end of the buffer decode as 0n instead of throwing, so the loop runs to the declared count. The result is a fatal, uncatchable heap OOM. The byte string decoder already guards this with a remaining length check; the array and map branches do not.
## Affected
packages/evolution/src/CBOR.ts decodeArrayAt definite branch (L1942-1951)
packages/evolution/src/CBOR.ts decodeMapAt definite branch (L1996-2025)
reference for the correct guard: decodeBytesAt (L1865)
## Fix
Before allocating or looping, bound the declared length by the remaining bytes (each array element needs at least 1 byte, each map entry at least 2), and throw a CBORError when the declared length exceeds what remains. Mirror the existing byte string check.
## Regression test
- given: Data.fromCBORHex("d8799a7fffffff") (7 bytes, declares ~2.1 billion elements)
- before fix: process aborts with a fatal heap OOM (uncatchable)
- after fix: throws a bounded CBORError that a caller can catch
- control: the byte string case (5a7fffffff) already throws and should stay throwing
Must FAIL on main today and PASS after the fix.
## Reference
Report 8
Hướng dẫn đóng góp
Hướng nghiên cứu
Đọc packages/evolution/src/CBOR.ts, bắt đầu với decodeBytesAt rồi đến các nhánh độ dài xác định của decodeArrayAt và decodeMapAt. Chạy thử Data.fromCBORHex("d8799a7fffffff") và trường hợp đối chứng của byte-string; hoàn tất khi các độ dài được khai báo quá lớn ném ra một CBORError có thể bắt được mà không cố gắng cấp phát hoặc lặp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- security
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 86/100