Skip to content

Reject truncated payloads across all conversion paths - #884

Merged
Brian Caswell (demoray) merged 2 commits into
microsoft:mainfrom
demoray:bcaswell/reject-truncated-conversions
Oct 12, 2026
Merged

Brian Caswell (demoray) merged 2 commits into
microsoft:mainfrom
demoray:bcaswell/reject-truncated-conversions

Conversation

@demoray

Copy link
Copy Markdown
Collaborator

Summary

Reject truncated payloads across all image conversion paths.

#883 identified that a LiME record could declare a larger range than its payload contained. `std::io::copy` returned the number of bytes copied, but the result was ignored, allowing conversion to succeed with zero-padded or incomplete output.

Reviewing the other conversion paths found the same issue in:

  • LiME-to-raw conversion.
  • Compressed AVML-to-LiME conversion.
  • Compressed AVML-to-raw conversion.

Compressed records could also omit or provide an incorrect eight-byte compressed-length trailer. The readers previously skipped the trailer with `seek`, which can succeed beyond EOF.

Changes

  • Require bounded copies to produce exactly the declared uncompressed size.
  • Return `UnexpectedEof` when a LiME or compressed payload ends early.
  • Read the existing compressed-length trailer instead of seeking over it.
  • Validate that the trailer matches the number of compressed bytes consumed.
  • Add regression tests covering truncated LiME payloads, truncated compressed payloads, missing trailers, and incorrect trailer values.

This does not change the LiME or compressed AVML wire formats. Valid existing images remain compatible; malformed images that were previously accepted now fail conversion.

Validation

  • `cargo test --no-default-features --features convert`
  • `cargo clippy --no-default-features --features convert --all-targets -- -D warnings`

@demoray
Brian Caswell (demoray) merged commit 7811351 into microsoft:main Oct 12, 2026
7 checks passed
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.

2 participants