hardening: return Err instead of panic in ssz_decode_fixed_vec#21
Open
MegaRedHand wants to merge 1 commit into
Open
hardening: return Err instead of panic in ssz_decode_fixed_vec#21MegaRedHand wants to merge 1 commit into
Err instead of panic in ssz_decode_fixed_vec#21MegaRedHand wants to merge 1 commit into
Conversation
MegaRedHand
commented
Mar 31, 2026
| .chunks_exact(item_size) | ||
| .map(Self::from_ssz_bytes) | ||
| .collect() | ||
| Err(libssz::DecodeError::NotFixedSize) |
Contributor
Author
There was a problem hiding this comment.
This is the equivalent of ssz_decode_fixed_vec but in the derive macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SszDecode::ssz_decode_fixed_vec) and the derive-generated override calledchunks_exact(0)when invoked on a variable-size type, causing an unconditional panic (division by zero inchunks_exact).DecodeError::NotFixedSizevariant and uses it to returnErrinstead of panicking in both code paths.is_fixed_size()before callingssz_decode_fixed_vec, so this change is purely defensive. It protects against direct external misuse of the API.Changes
crates/ssz/src/error.rsNotFixedSizevariant toDecodeErrorcrates/ssz/src/decode.rsitem_size == 0checkcrates/ssz-derive/src/lib.rschunks_exactfallback withErr(NotFixedSize)Test plan
cargo build --workspace --all-targets --exclude spec-testscargo clippy --workspace --all-targets --exclude spec-tests -- -D warningscargo test --workspace --exclude spec-testscargo test --workspace --exclude spec-tests --no-default-features --features alloccargo check -p libssz -p libssz-types -p libssz-merkle --target thumbv7m-none-eabi --no-default-features --features alloc