deserialize: validate offsets for structs, slices, lists (zeam #843)#63
Open
ch4r10t33r wants to merge 2 commits into
Open
deserialize: validate offsets for structs, slices, lists (zeam #843)#63ch4r10t33r wants to merge 2 commits into
ch4r10t33r wants to merge 2 commits into
Conversation
Malformed peer-supplied SSZ could slice past the buffer and panic in struct second pass, variable []T decode, variable arrays, and List sszDecode. - Mirror array-deserializer guards: alignment, prefix in bounds, start/end ordering. - Struct: bounds-check fixed-field reads and variable-field slices; require first var offset to match fixed-prefix length. - Union: require non-empty payload before reading selector. - utils.List: fixed-size path rejects ragged length and count > N; dynamic path bounds-checks offset prefix. Adds regression tests for struct offsets past the buffer. Closes blockblaz/zeam#843 when consumed downstream.
g11tech
approved these changes
May 8, 2026
gballet
requested changes
May 9, 2026
Collaborator
gballet
left a comment
There was a problem hiding this comment.
Test coverage is too low given the amount of error returns that were added:
┌─────────────────────────────────────────────────────────────────────────────────────┬───────────────────┐
│ Code path │ Tested? │
├─────────────────────────────────────────────────────────────────────────────────────┼───────────────────┤
│ Struct variable-field start > serialized.len (line 634) │ ✅ both new tests │
├─────────────────────────────────────────────────────────────────────────────────────┼───────────────────┤
│ Struct fixed-field overflow (lines 600/608/612) │ ❌ │
├─────────────────────────────────────────────────────────────────────────────────────┼───────────────────┤
│ Struct start > end / start < indices[prev] / first-field start != i (lines 635-637) │ ❌ │
├─────────────────────────────────────────────────────────────────────────────────────┼───────────────────┤
│ Variable array path (lines 461-475) │ ❌ │
├─────────────────────────────────────────────────────────────────────────────────────┼───────────────────┤
│ Variable []T slice path (lines 524-558) — incl. the new n_items == 0 rejection │ ❌ │
├─────────────────────────────────────────────────────────────────────────────────────┼───────────────────┤
│ Union 1-byte check (line 645) │ ❌ │
├─────────────────────────────────────────────────────────────────────────────────────┼───────────────────┤
│ utils.List ragged length + n > N (utils.zig:74-76) │ ❌ │
└─────────────────────────────────────────────────────────────────────────────────────┴───────────────────┘
- Remove minimum_zig_version from build.zig.zon (follow-up PR per maintainer). - Variable array: use .little; misalignment -> error.OffsetAlignment; drop redundant size vs len check. - Variable []T: .little; misalignment and n_items==0 -> OffsetAlignment. - Add regression tests for struct fixed overflow, nested truncation, ordering cases, variable array/slice paths, union empty guard (minInLength 0), List ragged and count>N; fix List test leaks with defer deinit. Addresses blockblaz#63 (review)
Author
|
@gballet I have addressed your comments. |
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.
Problem
Peer-supplied SSZ with invalid offset tables could slice past the buffer and panic during
deserialize(struct variable fields, variable[]T, variable arrays, andutils.Listdecode). See zeam#843.Change
start <= end, monotonic offsets.[]T: validate first/second offsets, item count, and each subsequent offset read before slicing.start <= end, offsets within buffer, monotonicity, andindices[0] == ifor the first variable field.serialized.len >= 1before reading the selector byte.utils.List.sszDecode: fixed-size items reject ragged length andn > N; dynamic path bounds-checks the offset-prefix length before slicing.Tests / tooling
build.zig.zon:minimum_zig_version = "0.16.0"(matches CI; satisfies anyzig when present).Downstream
After merge, zeam can switch from a vendored copy back to a
build.zig.zongit+dependency on the new commit.