Skip to content

RAR volumes read each byte once: the signature probe is the first piece - #313

Merged
xbmc4lyfe merged 6 commits into
mainfrom
rar-volume-head-once
Nov 27, 2026
Merged

xbmc4lyfe merged 6 commits into
mainfrom
rar-volume-head-once

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

Why

Prybar's strace -f -k of a 500 MB, 10-volume RAR5 set showed the first 1 MiB of every volume read twice: once by Volume::open_file → probe_signature (MAX_SFX + 8 bytes, even when the signature is at offset 0), and again by Source::fill as the reader's first piece. part01 also paid for the checked route's own 1 MiB + 8 probe. A big stored part copied by position (stored_parallel, ≥ 64 MiB) read that MiB a third time.

What

  • Volume opening (probe_head) reads the signature window once and seeds the reader's first Source piece with those bytes. If a head was read already (the format sniff's 1 KiB, the checked probe), it is kept, and only what the signature search still needs past it is read. SFX detection is unchanged: the same SignatureParser over the same MAX_SFX + 8 window.
  • checked_route recognizes a RAR from its 1 KiB head when the signature is there and hands those bytes to the volume through HeldSignature. The full-window probe runs only for a later signature (SFX).
  • extract::run / list / list_detailed keep the file and head that sniff read (sniff_held). inspect keeps its probe and handle.
  • stored_parallel: batch::stored_detailed takes the bytes the volume already holds (Volume::held_at), hashes and writes them first, and reads only the rest.
  • The budgeted catalogue path (open_catalogue) is unchanged: it reads 8 bytes, and the window only on a mismatch.

The catalogue pass and then extraction that Prybar saw on part01 are two separate API calls by the caller, so this PR can't merge them. Each one now reads part01's head once.

Measured (strace -f -ff -y, release build, rustyget-x86-a; stored RAR5 sets made by a generator)

set before: read / unique / dup after: read / unique / dup
500 MB, 10 × 50 MB 534,775,489 / 524,288,619 / 10,486,870 524,288,625 / 524,288,619 / 6
1 GB, 10 × 100 MB (stored_parallel) 1,069,548,710 / 1,048,576,619 / 20,972,091 1,048,576,625 / 1,048,576,619 / 6

Before, each volume read 1,048,584 extra bytes (2,097,106 with stored_parallel). After, the only repeat is 6 bytes on part01, from the ISO 9660 sniff at 32 KiB.

Tests

A #[cfg(test)] counter (rar5::reader::VOLUME_READS, fed by read_volume, which both the reader and batch::stored_detailed use) records every volume read. assert_read_once checks that each volume's reads follow on from each other with no repeats and end at its length.

  • extract::read_once::a_rar5_set_reads_each_volume_once: 3 volumes, with and without a 100 KB SFX prefix, 1 and 4 threads
  • extract::read_once::the_checked_route_reads_each_volume_once: run_with_policy, with and without an SFX prefix
  • extract::read_once::a_big_stored_part_reads_its_volume_once: the stored_parallel path
  • extract::read_once::a_rar4_set_reads_each_volume_once: the rar4-volumes fixtures
  • extract::read_once::a_rar5_listing_reads_the_first_volume_head_once: list and inspect
  • extract::read_once::a_signature_past_the_window_is_not_found: a stub over MAX_SFX is still not a RAR, and one exactly at the edge is still found
  • batch::positional_tests::a_held_head_is_copied_and_only_the_rest_is_read

Revert check: with only the counter applied to old main, all five read-once tests fail (read (0, 1048576) with 1024 read so far, read twice: (0, 1048576) and (0, 1048584)). Local cargo nextest run --workspace --locked: 2930 passed.

Clean-room: no third-party code read or used.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

Opening a RAR volume read its first MiB twice: once to find the signature
(up to MAX_SFX + 8 bytes in, for a self-extractor) and again as the
reader's first piece. The probe's bytes now seed the reader, so every
volume's head is read once, SFX detection unchanged.

- The checked route recognizes a RAR from its 1 KiB head when the
  signature is there, and hands the bytes to the volume; the whole
  window is probed only for a later signature.
- extract::run and list keep the file and head the format sniff read;
  inspect keeps its probe and handle.
- A big stored part copied by position (stored_parallel) takes the
  bytes the volume read with the headers rather than reading them again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj
@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T02:07:12.462453Z 1a58155 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 523a622e96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 226790f8a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 5d462cf4c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 1fb396b94b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…-volume-head-once

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj
@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 1a58155417

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

Local CI (.claude/skills/ci-local/run.sh --host rustyget-x86-a) on the exact head 1a581554, which is up to date with origin/main:

==> fmt --check                                             ok (4s)
==> clippy -D warnings                                      ok (15s)
==> clippy -D warnings (persistent-partials)                ok (17s)
==> test (workspace)                                        ok (312s)
==> test (persistent-partials)                              ok (397s)
==> doctests                                                ok (1s)
==> doctests (persistent-partials)                          ok (2s)
ALL GATES PASSED @ 1a581554 (full)

Codex review on 1a581554: no findings.

@xbmc4lyfe
xbmc4lyfe merged commit 2d03962 into main Nov 27, 2026
5 of 7 checks passed
@xbmc4lyfe
xbmc4lyfe deleted the rar-volume-head-once branch November 27, 2026 02:19
xbmc4lyfe added a commit that referenced this pull request Nov 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj
xbmc4lyfe added a commit that referenced this pull request Nov 27, 2026
…kb and 7z x -so hand over of a failing member (#317)

* Opt-in unverified output: UnverifiedOutput::Emit writes, prints and streams what UnRAR and 7-Zip hand over of a failing member

- Options::unverified_output (whole-archive RAR runners, RarSession extraction with keep_broken): a RAR member cut
  off by a missing volume keeps every byte UnRAR 7.30 `x -kb` keeps (RAR 3.x/4.x: LZ tokens starting in the last
  30 bytes left out; RAR 5.0: the partial block decoded, symbols in the last 128 bits left out, a block with under
  1024 bytes skipped; observed on 50 cut points).
- RarPrintOptions::unverified_output (`unrar p`): a member failing on its own data prints what was decoded of it;
  RarEntryOutcome::unverified_bytes says how many bytes went out.
- sevenzip::print_selected_with_options + SevenZipPrintOptions (`7z x -so`): a failing 7z member streams what
  7-Zip 26.06 streams (CRC failure: all; data error / cut folder: the bytes before it); Summary::unverified.
- SelectOptions::unverified_output (SelectedEntry): 7z as above; RAR 3.x/4.x unsupported VM filters streamed
  unfiltered; read fails with UnverifiedWritten { bytes, cause }.
- LZMA readers hand out the bytes decoded before a data error, then the error.

Defaults unchanged. tests/unverified_output.rs checks each route against the reference tools' output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

* Codex on #317: 7z unverified members keep archive order, output errors propagate, LZMA errors at the last byte stay

- A member failing behind ones held for the folder's CRC is queued behind them (printed in archive order).
- wrong_password() returns a result: an output error replaying held members ends the run.
- The LZMA readers put a data error off only when the caller asked for more than was made; one asking for exactly
  the bytes left never reads again, so the error is returned then (default outcomes unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

* Merge origin/main; unverified_output in the new rar5_link_password literal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

* Codex on #317: cut-member output faults end the run, printing hands over buffered bytes, unfiltered prerequisites don't stop a selected read

- Run::emit_unverified returns a fault writing the flushed bytes as the run's terminal error.
- RarSession decoding under UnverifiedOutput::Emit flushes what a failing decoder still buffers before the failure
  (printing and keep_broken extraction get every byte decoded).
- SelectedEntry (Emit) goes on past a solid prerequisite written unfiltered; only the selected member's own
  unfiltered write fails the read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

* Codex on #317: a split part failing its own checksum hands over what was decoded under Emit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

* unverified_output in the Options literal #313 added

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

* unverified_output in the Options literals #316 added

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant