Skip to content

RAR5: plan and frame a dead volume from its siblings, exact or virtual (RustyGet) - #369

Merged
xbmc4lyfe merged 3 commits into
mainfrom
rar5-dead-volume-planner
Nov 30, 2026
Merged

xbmc4lyfe merged 3 commits into
mainfrom
rar5-dead-volume-planner

Conversation

@xbmc4lyfe

@xbmc4lyfe xbmc4lyfe commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Implements the RustyGet request (b): placing a dead RAR 5.0 volume of a stored set, and framing it from a readable sibling. Clean-room: written from the prose behavioural spec, the RAR 5.0 format description and observed behaviour of rar/UnRAR output.

API (zipfast::rar5, docs: docs/rar5-dead-volume.md)

  • plan_dead_volumes(&[VolumeState], &MemberInfo, &PlanOptions) -> DeadVolumePlans { plans, stop: Option<PlanStop> }
    • VolumeState::{Readable(ReadableVolume { version, len, part_start, part_len, split_before, split_after, framing_intact }), Dead(DeadVolume { nzb_size, exact_len, part_crc }), Unknown}
    • MemberInfo { name, unpacked_size, headers_encrypted, encrypted, compressed, blake2sp }, PlanOptions { prefer_exact }
    • each DeadVolumePlan gives the dead index, template index (and its layout), member offset, part length, volume/head/tail lengths, width_shift, last/last_fit, mode: FrameMode::{Exact, Virtual} and reason: ModeReason::{PartCrcAndExactLength, VirtualRequested, NoPartCrc, NoExactLength, ExactRefused(ExactRefusal)}
    • DeadVolumePlan::with_part_crc(crc) for a CRC learned later
  • frame_dead_volume(&DeadVolumePlan, &MemberInfo, &FrameInput { template_head, template_tail, earlier_parts_complete, borrowed_len }) -> Result<DeadVolumeFrame, FrameRefusal>
    • Exact: rebuild_volume_headers (byte for byte as rar wrote it). If it is refused, does not match the plan, or does not read back, the frame falls back to Virtual and says why.
    • Virtual: main header without its locator/extra area, the file header with the given CRC32 or none (flag cleared, 4 bytes dropped), only the end header behind the part
    • every frame is read back through VolumeMapBuilder with zeros for the part, and checked as the spec's "what is verified" lists, plus the member's full name and unpacked size; a template with a redirection (symbolic or hard link) record is refused
  • whole_file_crc32(&[(crc, len)]): part CRC32s combined in order, for a dead last volume

Every refusal is typed: PlanStop (Unusable(..), FirstNotReadable, NotReadable, NoTemplate { NoSibling | Disagree | FramingDamaged }, MayBeLast, LastNeedsPar2Len, LastLenMismatch, LastTooLarge, NzbSizeMisfit, ExactLenMisfit, PastMemberEnd, MoreThanMember, MemberSizeMismatch (drops every earlier plan), Rar4LastVolume, MixedVersions, Inconsistent, EmptySet), plus FrameRefusal (UnsupportedVersion, TemplateChanged, Template(TemplateFault), LastVolumeIncomplete, LastVolumeNeedsCrc, BorrowedLengthDiffers, Overflow, ReadBack(..)).

Review fixes (second commit)

  • The parts must add up to the member: a closing readable volume, or a sum past the member after a dead plan, stops with MemberSizeMismatch and drops every earlier plan. Past an Unknown volume, the sum cannot be checked.
  • A dead last volume is at most a middle volume's part (LastTooLarge).
  • Readable volumes after the first must be split-before while the member is open.
  • The read-back compares the full name and unpacked size; TemplateFault::Redirection refuses symbolic and hard link records.
  • An exact frame that fails the read-back falls back to Virtual (ExactRefused(ReadBack)).

Tests (tests/rar5_dead_volume.rs, 18 tests)

  • Real rar 7.30 stored set (committed, 148 KB, with quick open records). Each middle volume is deleted and rebuilt: Exact matches the original byte for byte, and Virtual (with and without CRC) extracts byte-identical. The last volume is rebuilt Exact from par2 + whole_file_crc32, and Virtual. The par2 bare/framed/mismatch rules and NZB slack are checked.
  • Width shift: a synthetic 134-volume set with rar's fixed volume size. Shift +1 (128 from 127) and same-width preference. Shift -1: volumes 1..127 all dead, rebuilt from 128, exact and virtual, and the set extracts.
  • Every PlanStop, TemplateFault and frame refusal is reached. The review's proof cases (sum mismatch, oversized last, missing split-before, other dir/size/links) are now tests of the fixed behaviour. Hostile input: 20k random extreme sets; bit flips at every byte of a real template plus every cut; junk heads; contradictory siblings.
  • UnRAR 7.30 (macOS build) also tests the virtual-framed sets OK (manual check, not in CI).

Related suites pass: rar5_volume_headers, rar5_volume_tail, uniform_volumes, last_volume_identity, rar4_volume_tail, container_rebuild*. fmt and both clippy runs pass.

Not done here: the spec's "streamable video or nested archive" check is RustyGet policy and stays with the caller (noted in the docs).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@xbmc4lyfe
xbmc4lyfe force-pushed the rar5-dead-volume-planner branch from 02a3246 to 2449e7e Compare November 30, 2026 16:34
xbmc4lyfe and others added 3 commits November 30, 2026 11:34
…l (RustyGet)

plan_dead_volumes places each dead volume of a stored RAR set: the member offset from the earlier parts, the template
from the nearest agreeing middle siblings (same volume number width preferred, shifted across a width boundary, an
identical intact sibling for damaged framing), the NZB and par2 length rules, and the last-volume rule. It stops at
the first problem with a typed PlanStop and keeps the plans made before it. Each plan reports its mode (Exact or
Virtual) and a typed reason.

frame_dead_volume builds the frame: Exact through rebuild_volume_headers, or Virtual (main header without its
locator, file header with the given CRC32 or none, end header only). It reads the frame back through the RAR 5.0
header reader with zeros for the part. Every refusal is typed. whole_file_crc32 combines part CRC32s for a dead
last volume.

Clean-room: from the prose spec, the RAR 5.0 format description and observed rar/UnRAR behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
… template's file (review)

- The parts must add up to the member: when a readable volume closes it, or the sum passes it after a dead volume
  was planned, planning stops with MemberSizeMismatch and drops every earlier plan.
- A dead last volume holds no more than a middle volume's part (LastTooLarge).
- While the member is open, every readable volume after the first must be split-before.
- The read-back requires the member's full name and unpacked size; a template with a redirection (symbolic or hard
  link) record is refused (TemplateFault::Redirection).
- An exact frame that does not read back falls back to Virtual with ExactRefused(ReadBack).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
@xbmc4lyfe
xbmc4lyfe force-pushed the rar5-dead-volume-planner branch from 2449e7e to c7d22e9 Compare November 30, 2026 17:34
@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

Local CI (full, all gates: fmt, clippy ×2, tests ×2, doctests ×2) passed at c7d22e9, the exact head, up to date with main e48533a, on linux x86_64 (rustyget-x86-q), linux arm64 (rustyget-arm-g) and macOS arm64.

@xbmc4lyfe
xbmc4lyfe merged commit fa031ee into main Nov 30, 2026
0 of 7 checks passed
@xbmc4lyfe
xbmc4lyfe deleted the rar5-dead-volume-planner branch November 30, 2026 18:02
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