fix(payload): reject zero-byte arbitrary input for Block#1892
Draft
goxberry wants to merge 1 commit into
Draft
Conversation
This was referenced May 22, 2026
Contributor
Author
This comment has been minimized.
This comment has been minimized.
`Block::total_bytes` is `NonZeroU32`, but the
`#[cfg(feature = "arbitrary")] impl Arbitrary for Block` previously
called `NonZeroU32::new(u32::arbitrary(u)?).expect("...")`. When the
fuzzer happened to produce a zero (which it can, by contract), the
expect panicked instead of rejecting the input.
The fix uses `.ok_or(arbitrary::Error::IncorrectFormat)?`, the
standard arbitrary-crate signal for "this input shape is invalid;
skip it and try another." The `bytes` allocation is also moved after
the rejection check so a rejected input no longer allocates first.
Adds `arbitrary_rejects_zero_total_bytes` as a regression test under
`#[cfg(all(test, feature = "arbitrary"))]`. The test was written
against the old code and panicked there; against the fixed code it
passes by matching `Err(arbitrary::Error::IncorrectFormat)`.
Reachable from `lading_fuzz`, which enables the `arbitrary` feature.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f42e36f to
c9ca68e
Compare
dfea61d to
69742f3
Compare
This was referenced May 22, 2026
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.

What does this PR do?
Fixes a latent panic in
lading_payload::block::Block::arbitrary(#[cfg(feature = "arbitrary")]). The previous implementation panicked when the fuzzer produced a zero foru32::arbitrary; the fix rejects that case viaarbitrary::Error::IncorrectFormatso the fuzzer skips the input and tries another.A regression test pins the new behavior.
The bug
u32::arbitraryis permitted by contract to return anyu32, including 0. When that happens,NonZeroU32::new(0)isNone, and.expect(...)panics. Reachable fromlading_fuzz, which enables thearbitraryfeature.The fix
Three changes:
NonZeroU32::new(...).expect(...)→.ok_or(arbitrary::Error::IncorrectFormat)?. This is the documented way to tell thearbitrarycrate "skip this input, it's malformed."bytesallocation moves below the rejection check, so a rejected input no longer allocates first.total_bytes.get()is used for theu.bytes(...)call, sincetotal_bytesis nowNonZeroU32.Regression test
arbitrary_rejects_zero_total_byteslives in a new#[cfg(all(test, feature = "arbitrary"))]submodule ofblock.rs. It constructsUnstructured::new(&[0u8; 16])— guaranteeingu32::arbitraryreads four zero bytes — and asserts the result isErr(arbitrary::Error::IncorrectFormat). The test was written against the old code first; there, it panicked exactly at the.expect(), confirming the bug.Motivation
Last targeted PR in the panic-cleanup phase of the stack started by #1882. After this lands, the only remaining work in
lading_payloadis the Cat-2 sites (~33.expect()sites that need function-signature changes to threadResultthrough) and the final quarantine drop. Those will be the next sub-stack.Related issues
Stacked on #1891.
Additional Notes
cargo build --all-targets --all-features✓cargo clippy --all-targets --all-features✓cargo test -p lading-payload --features arbitrary --lib✓ (245 passed including the new regression test)