Skip to content

Handle partial-word serde byte input - #3755

Open
1sgtpepper wants to merge 2 commits into
risc0:mainfrom
1sgtpepper:codex/from-slice-partial-word-error
Open

1sgtpepper wants to merge 2 commits into
risc0:mainfrom
1sgtpepper:codex/from-slice-partial-word-error

Conversation

@1sgtpepper

Copy link
Copy Markdown

Summary

Fixes #3754.

risc0_zkvm::serde::from_slice can currently panic when called with byte input whose length is not a complete number of u32 words, e.g. from_slice::<u32, u8>(&[0, 1, 2]).

This PR adds a small pre-check that returns Error::DeserializeUnexpectedEnd for partial-word input before attempting the bytemuck cast. It preserves the existing unaligned-but-complete byte-slice path.

Implementation note

This also changes the remaining bytemuck catch-all arm from a panic to Err(Error::NotSupported). The partial-word length precheck is the actual fix for this issue; the catch-all change keeps from_slice aligned with its Result API. If maintainers prefer the smallest possible behavior change, I can drop that part and leave the catch-all arm unchanged.

Tests

cargo fmt --check
git diff --check
RISC0_SKIP_BUILD=1 cargo test -p risc0-zkvm --lib serde::deserializer::tests -- --nocapture

RISC0_SKIP_BUILD=1 was needed in my Termux/Android environment because guest build scripts otherwise fail with UnsupportedPlatform("unknown OS: android").

@vercel

vercel Bot commented May 16, 2026

Copy link
Copy Markdown

@Kuhai9801 is attempting to deploy a commit to the Boundless Team on Vercel.

A member of the Team first needs to authorize it.

@1sgtpepper
1sgtpepper marked this pull request as ready for review May 16, 2026 15:27
@1sgtpepper
1sgtpepper requested a review from a team as a code owner May 16, 2026 15:27
@1sgtpepper 1sgtpepper closed this May 23, 2026
@1sgtpepper
1sgtpepper deleted the codex/from-slice-partial-word-error branch May 23, 2026 13:24
@1sgtpepper
1sgtpepper restored the codex/from-slice-partial-word-error branch May 23, 2026 13:33
@1sgtpepper 1sgtpepper reopened this May 23, 2026

This branch has not been deployed

No deployments
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.

serde::from_slice panics on partial-word byte slices

1 participant