Union deserialize on empty input throws TypeError instead of a decode error
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- data
Research direction
Start in the union type's value_deserializeFromBytes, where data.uint8Array[start] is read as the selector with no length check, then follow the this.types[selector] lookup. Add a check that at least one byte is available and throw a decode Error like the other size errors. Done when new UnionType([...]).deserialize(new Uint8Array([])) throws a clear Error rather than a TypeError, and the existing union tests still pass.
Written by the indexing model from the issue text.
Description
Describe the bug
UnionType.deserialize on an empty Uint8Array throws a raw TypeError instead of a stable SSZ decode error.
Root cause: value_deserializeFromBytes reads data.uint8Array[start] with no length check. On an empty buffer that value is undefined. The selector bounds check (selector > this.maxSelector) is false for undefined, so the code indexes this.types[undefined] and calls .value_deserializeFromBytes on it.
const selector = data.uint8Array[start];
if (selector > this.maxSelector) {
throw Error(`Invalid selector ${selector}`);
}
return {
selector,
value: this.types[selector].value_deserializeFromBytes(...),
};
Expected behavior
Reject empty / truncated Union input with a clear decode error (for example requiring at least 1 byte for the selector), similar to how other types report size errors. Do not throw TypeError: Cannot read properties of undefined.
Steps to Reproduce
import { UnionType, UintNumberType } from "@chainsafe/ssz";
const type = new UnionType([new UintNumberType(1), new UintNumberType(2)]);
type.deserialize(new Uint8Array([]));
Actual:
TypeError: Cannot read properties of undefined (reading 'value_deserializeFromBytes')
A one-byte selector with no payload already fails with a proper Error (BasicType invalid size ...), so only the empty-buffer path hits the TypeError.
Version
Reproduced on @chainsafe/ssz 1.9.1 (current master tip) with Node.js v22.23.4.
Related but different: #507 (None variant trailing bytes). This report is only about empty input producing an uncaught TypeError.
- Dominant language
- TypeScript
- Stars
- 62
- Forks
- 27
- Avg merge
- 2h 35m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ChainSafe/ssz
-
BitList deserialization with reuseBytes: true mutates the input bufferPossibly taken @yinbowen-dc claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
bitlist maxSize off by one and inconsistent progressive list default limitsPossibly taken @yinbowen-dc claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
SSZ Union Deserialization Vulnerable to Trailing Data for Certain VariantsPossibly taken @shadowzzed claimed this 75 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
-
Container SSZ deserialize on short/empty inputs throws RangeErrorMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 62/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ranxianglei/billion-context#7597 ·
Maintainers usually reply within 1 day
-
kubernetes-ingestor: fetchCRDMapping() runs even when crossplane.enabled is false, logging a 403 ERROR every runPossibly taken @kc9ddi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TeraSky-OSS/backstage-plugins#228 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
zmkfirmware/zmk#3571 ·
Maintainers usually reply within 10 days
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaPossibly taken @lijy91 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
libnativeapi/nativeapi#53 · 1 reaction ·
Maintainers usually reply within 1 day
-
area:hardware bug work:repair
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
jon-whiteroomsoftware/PXLBLZ-IDE#1269 ·