Repository navigation
fix: reject Union input without a selector byte - #568
Conversation
UnionType read the selector from an empty buffer as undefined, which passed the maxSelector check and failed later with a TypeError. Throw a decode error instead, as CompatibleUnionType does. Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kutluhaneth46
left a comment
There was a problem hiding this comment.
Thanks for picking up #567. The empty-range guard in both value_deserializeFromBytes and tree_deserializeFromBytes is the right place. Public deserialize / deserializeFromBytes go through the tree path on CompositeType, so UnionType.deserialize(new Uint8Array()) should now throw a real decode Error instead of TypeError on types[undefined].
One small test hardening idea: in the new "No selector byte" case, assert error instanceof Error (or that the message is not a TypeError-shaped stack). That locks the original bug class so a future refactor cannot silently regress to Cannot read properties of undefined while still matching the "selector byte" substring.
Otherwise the fix looks complete for the empty-buffer path.
spiral-ladder
left a comment
There was a problem hiding this comment.
lgtm, thanks for the PR
|
Thanks for the review, and to spiral-ladder for merging. Good point about the test: the new case matches on the message, so a regression that threw a |
Motivation
UnionType.deserializeon an empty buffer throwsTypeError: Cannot read properties of undefinedinstead of a decode error (#567).Description
The selector read from an empty buffer is
undefined. It passes theselector > this.maxSelectorcheck, andthis.types[undefined]fails later.value_deserializeFromBytesandtree_deserializeFromBytesnow throwUnion requires a selector bytewhenend <= start, asCompatibleUnionTypealready does ("CompatibleUnion requires a selector byte").Closes #567
Steps to test or reproduce
The new
No selector bytecase intest/unit/byType/union/invalid.test.tsruns throughrunTypeTestInvalid, so it covers struct deserialize, tree deserialize,toViewandtoViewDU. Its 4 tests fail without the fix and pass with it.In
packages/ssz, the full unit suite passes (2429 passed, 3 skipped).biome checkon the two changed files andtsc --noEmitreport nothing.🤖 Generated with Claude Code
https://claude.ai/code/session_014cRzwuyJe8BGwXowsQ3kpw