Skip to content

Add regression test and fuzz coverage for zero first offset in lists#29

Open
MegaRedHand wants to merge 1 commit into
mainfrom
test/zero-first-offset-regression
Open

Add regression test and fuzz coverage for zero first offset in lists#29
MegaRedHand wants to merge 1 commit into
mainfrom
test/zero-first-offset-regression

Conversation

@MegaRedHand

Copy link
Copy Markdown
Contributor

Context

leanEthereum/leanSpec#1175 reports that leanSpec's SSZ variable-length list decoder accepts first_offset == 0: the element count computes to 0 while the offset/scope boundary describes one element spanning the whole input. It fails there only by accident, at the wrong layer.

libssz is not affected

decode_variable_length_items_with_max already rejects this up front via the num_items == 0 check (crates/ssz/src/decode.rs), returning InvalidFirstOffset before any offsets or element bodies are parsed. ContainerDecoder is stricter still: the first offset must equal the fixed-part length exactly.

Changes

  • Regression test (vec_of_vecs_zero_first_offset): pins the rejection using the issue's exact payload 00000000aabbccdd, plus the bare 00000000 case.
  • Fuzz coverage: offset_adversarial only exercised ContainerDecoder (its fields are Vec<u8>, which decodes as raw bytes with no inner offset table), so the list offset-table path had no raw-bytes fuzz coverage anywhere. Added Vec<Vec<u8>> and a container holding one, matching the target's documented intent of covering zero-offset patterns.

leanEthereum/leanSpec#1175 reports that leanSpec's SSZ list decoder
accepts first_offset == 0, deriving a zero element count while the
offset/scope boundary describes one element spanning the whole input.
libssz already rejects this up front (the num_items == 0 check in
decode_variable_length_items_with_max), but nothing pinned that
behavior.

Pin it with a regression test using the issue's exact payload, and
extend the offset_adversarial fuzz target with list-of-variable-length
items types: it previously only exercised ContainerDecoder, never the
list offset-table path where this class of bug lives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant