Skip to content

Persistent-partial sessions honour damaged_input (Salvage/Resync); members bound by header position - #321

Open
xbmc4lyfe wants to merge 4 commits into
mainfrom
persistent-salvage
Open

xbmc4lyfe wants to merge 4 commits into
mainfrom
persistent-salvage

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

Persistent-partial sessions (ProgressiveSession::new_partial, RustyGet's direct unpack) now honour extract::Options::damaged_input (Salvage, Resync), as #316 did for ordinary progressive sessions. Refuse (the default) is unchanged.

Behaviour

Journal binding

The key used to be (ordinal, SHA-256 of the first header's bytes), and adoption compared every header witness byte for byte. Damage breaks both: a damaged header's bytes change once repaired, and damage can hide or invent a member, so the ordinals after it move. Under Salvage/Resync:

first header ordinal identity
whole, no damage before it in this session member ordinal domain v1 + header bytes (unchanged)
whole, after damage MemberKey::POSITIONAL (u64::MAX) domain at/v1 + volume + header offset + header bytes
read past as damage MemberKey::POSITIONAL domain salvaged-at/v1 + volume + header offset
  • A whole header is looked up under ordinal key, then positional, then salvaged-position, and created under the first (or the positional one after damage). A damaged header uses only the salvaged-position key.
  • (a) A restart over the same damaged bytes derives the same keys and adopts the same members, deterministically.
  • (b) Once repaired, the header is found under the salvaged-position key. Adoption parses the recorded (damaged) witness and the repaired header and requires the same member: name, unpacked/packed size, data offset, method, CRC32/BLAKE2sp, split flags, encryption parameters, host. Times and attributes are left out because they change no output byte. If they match, the member is rebound and resumes. If not, the session ends with Partial(BindingMismatch(Member)), whose context names the header's volume and offset, before anything is written. Data is never mixed across members. Later parts' witnesses follow the same rule; a changed part is BindingMismatch.
  • Members after the damage are found under their positional key whatever came before; members the damage hid are created.

Compatibility

  • Refuse: the lookups, keys and state bytes are exactly as before (whole_headers_keep_their_keys pins the key derivation).
  • State format: salvaged witnesses are listed in a new header-witness section (tag 0x5A, version 1), written only when one exists and parsed as it stands on reopen. Every other state is byte-identical, so existing states and anchors load and adopt unchanged. Older builds refuse a state carrying the section with StateVersion (unknown tag), and an unknown section version is StateVersion too.
  • Resume a set with the same damaged_input choice: Refuse does not look up positional keys.

Tests

tests/persistent_salvage.rs (new):

  • salvage_and_resync_extract_what_the_progressive_session_does
  • a_header_still_to_come_is_waited_for_and_one_in_a_hole_stops_the_session
  • a_restart_over_the_same_damaged_bytes_binds_the_same_members
  • a_repaired_header_rebinds_to_the_same_member (RAR5 + RAR4, mid-member resume)
  • a_repaired_continuation_header_is_the_same_part
  • a_header_repaired_into_another_member_is_refused
  • a_member_found_again_after_its_ordinal_moved
  • a_salvaged_state_reopens
  • refuse_is_unchanged_in_a_persistent_session
  • whole_headers_keep_their_keys
  • corrupting_every_37th_offset_never_panics_and_restarts_the_same

There is also partial::tests::ledger::salvaged_witnesses_persist_in_their_own_section (section layout, strict versus salvaged parse, version and index rejection). a_persistent_session_still_refuses_damaged_headers is removed because it is superseded.

Revert-check: on origin/main, 8 of the 11 new integration tests fail. The 3 that pass are refuse, key compatibility and hostile. With the witness leniency disabled, both repair tests fail.

Known limit (documented): a damaged mode applied as an output's permissions can make the output unreadable to its owner, and a later adoption cannot get past that. The same is true of a clean member stored with mode 000.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj

…mbers bound by header position

ProgressiveSession::new_partial now reads past damaged RAR 4.x / 5.0 headers under
ProgressiveOptions::extract.damaged_input as an ordinary progressive session does: the same members,
bytes and ProgressiveEvent::HeaderDamaged events, with the same hole rule (NotYet waits, a header in a
Hole is HeaderHole, no resync across a hole). Refuse (the default) is unchanged.

Journal binding: a member whose first header was read as damage is keyed by its position (volume,
header offset; ordinal MemberKey::POSITIONAL), and a whole header after damage in the session by
position and bytes, since damage can move the ordinals of later members. A whole header is looked up
under its ordinary key, then its positional key, then the salvaged-position key, so a restart over the
same damaged bytes and a resume over a header repaired since both find the member. Adoption accepts a
witness that differs from the recorded one only when either was salvaged and both parse to the same
member (name, sizes, data offset, method, checks, split flags, encryption, host); otherwise
BindingMismatch(Member), naming the header, before anything is written.

State format: salvaged witnesses are listed in a new header-witness section (tag 0x5A, version 1),
written only when one exists, and parsed as they stand on reopen. Every other state is byte-identical;
older builds refuse a state with the section as StateVersion.

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-27T03:27:34.177729Z 5a0a8f8 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b512c8798

ℹ️ 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".

Comment thread src/progressive/session/salvage.rs Resolved
…ain header drops its recorded bytes

A file header whose type byte was hit so that it reads as a main header is dropped (its data passed over); its
bytes stayed in the persistent session's header buffer, so the next header was not contiguous and the session
ended with SourceContract. They are now dropped with the frame. Case "rar5 file read as main" added.

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. Another round soon, please!

Reviewed commit: afa870a10f

ℹ️ 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: 5a0a8f8974

ℹ️ 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".

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