Skip to content

7zAES over Copy: map and restart every member of the folder, not only the first (RustyGet) - #372

Closed
xbmc4lyfe wants to merge 3 commits into
mainfrom
sevenzip-cbc-every-member
Closed

xbmc4lyfe wants to merge 3 commits into
mainfrom
sevenzip-cbc-every-member

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

Closes #365 (RustyGet#816, prybar#228).

In a 7zAES-over-Copy folder, members after the first now map to their folder's CBC blocks, and can be read by range and restarted. Before, only the member at folder offset 0 had a direct mapping.

How it works

  • New mapping: a new variant, OutputMapping::CbcSkip { skip }, is used for a member at folder offset s > 0. The enum is #[non_exhaustive].
  • Pieces: they start at the block before the member's first block, or at folder offset 0 when s < 32, and end at the end of the block holding the member's last byte.
  • Offsets: output byte o is stream byte o + skip, which is folder byte s + o.
  • IVs: each block decrypts with the ciphertext block before it as its IV, and the folder IV for folder block 0.
  • First member unchanged: it keeps CbcBlocks, so every existing check on that variant behaves as before.
  • Read planning: packed_spans, MemberReader, member_restart/open_at (StoredCbc / Block16, stream_start = s) and probe all handle the skipped prefix.
  • Feed decoder: it refuses these members with the typed FeedUnsupported::CbcSkip. Before, they were refused as UnmappedCipher.
  • Hostile input: member offsets are now summed with checked arithmetic, and a folder whose packed size ends before a member's last block is rejected as Malformed.

Visible changes for later members

  • Their packed_size now counts their blocks plus the IV block, so neighbouring members' pieces overlap by 16 to 32 bytes.
  • Persisted-partial identities, which hash the pieces, will differ from before.

Tests

tests/sevenzip_cbc_members.rs, run on a single archive and a 3-volume split. The fixtures were made with 7-Zip 26.06 and the README gives the commands. The tests cover:

  • mapping of every member;
  • first-member behaviour unchanged;
  • byte-exact range reads using exactly the minimal blocks;
  • a counting MemberReader whose reads equal packed_spans;
  • CRC32 verification, including wrong-password and corrupted-CRC cases;
  • what member_restart reports;
  • the feed decoder's typed refusal;
  • malformed folder sizes and hand-edited maps, none of which panic.

tests/member_map_7z.rs is updated for the new mapping.

Clean-room: written from the 7z format docs and AES-CBC, plus the behaviour of the 7-Zip binary. No source was read.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

xbmc4lyfe and others added 3 commits November 30, 2026 13:54
… the first (#365)

A later member of a 7zAES-over-Copy folder (folder offset s > 0) now maps as
OutputMapping::CbcSkip { skip }: its pieces are the folder ciphertext from the
block before the one holding s (0 when s < 32) to the end of the block holding
its last byte, and output byte o is stream byte o + skip (folder byte s + o).
packed_spans, MemberReader, member_restart / open_at (StoredCbc / Block16 with
stream_start = s) and probe handle it; the feed decoder refuses it with
FeedUnsupported::CbcSkip. The first member stays CbcBlocks, unchanged. Member
offsets use checked arithmetic, and a folder whose packed stream ends before a
member's last block is Malformed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
…r-block phase, probe and small-offset tests

- A later member whose blocks run past the folder's packed stream stays
  OutputMapping::None (readers refuse it) instead of failing the whole map;
  only the first member running past is Malformed, as before.
- open_at takes the block phase from the CbcSkip prefix; member_restart,
  open_at and MemberReader validation reject a folder offset the prefix does
  not put on a folder block (new OpenAtError::Malformed).
- Tests: damaged pack sizes map with f.bin unmapped and a-e reading exact,
  extraction of a whole-block cut keeps a-e; a hand-edited prefix; probe on
  a later member named .mkv (media.7z); members at folder offsets 5, 16, 32,
  39, 48, 81 (small.7z) read every range exact.
- Docs: CbcSkip block-0 note, extract-member-from refusals, member-map damage
  row, persisted DirectPartial keys of such members.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
@xbmc4lyfe
xbmc4lyfe force-pushed the sevenzip-cbc-every-member branch from 8ef252a to a9e8d3e Compare November 30, 2026 19:55
@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

Merged onto main via signed fast-forward stack at 2f47bcc..8fcc902 after clean-room review and macOS + Linux workspace/doctest gates (including persistent-partials).

@xbmc4lyfe xbmc4lyfe closed this Dec 1, 2026
@xbmc4lyfe
xbmc4lyfe deleted the sevenzip-cbc-every-member branch December 1, 2026 00:58
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.

7zAES over Copy: map and restart every member of the folder, not only the first

1 participant