Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 49 additions & 13 deletions docs/compat-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ restart_from_first_volume: false,
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down Expand Up @@ -147,21 +148,56 @@ run writes nothing. The whole-archive runners for RAR, 7z, ZIP and tar, `RarSess
sessions honour it (a progressive session still stops at the refused link, as without the option).
`tests/links.rs` and `tests/rar5_links.rs` check these points.

## Encrypted RAR 5.0 links and a wrong password (no option)
## `encrypted_links`: encrypted RAR 5.0 links and a wrong password

`rar a -p` encrypts file data but leaves headers in the clear, so a link member's target (its redirection record)
is readable whatever the password. 7-Zip 26.06 creates such links with a wrong password; UnRAR 7.30 reports the
wrong password for the member and creates nothing. zipfast does as UnRAR does, on every route (`extract::run*`,
`RarSession` test and extraction, progressive sessions), and has no switch for 7-Zip's behaviour: a caller that
wants it (Prybar's 7z mode) handles it itself.

A redirection member whose header carries an encryption record (Unix or Windows symbolic link, junction, hard
link, file copy) is placed, or passes a test, only when its password check value verifies the password. No
password fails it as `RarFailure::PasswordRequired`, a wrong one as `RarFailure::WrongPassword`, as an encrypted
data member fails; nothing is created. A record without a check value, or with a check value whose checksum doesn't
match, can't verify any password, and a link has no data to check one against: the member is refused as
`RarFailure::EncryptedIntegrity` with `RarIntegrityReason::UnverifiableLinkPassword`, even with the right password.
A progressive session stops at such a member, as it does at a wrong password.
is readable whatever the password. UnRAR 7.30 reports the wrong password for the member and creates nothing;
7-Zip 26.06 doesn't check the password for a link at all. `Options::encrypted_links` picks one:
`EncryptedLinks::Verify` (the default), `EncryptedLinks::VerifyFirst` (UnRAR's reporting order, for Prybar's unrar
mode) or `EncryptedLinks::PlaceUnverified` (7-Zip's, for Prybar's 7z mode).
It applies on every route: `extract::run*`, `RarSession::extract_selected` and `extract_selected_controlled` (from
the `Options` they take), `RarSession::test_selected` (from `RarSessionOptions::encrypted_links`, as it takes no
`Options`), and progressive sessions (from `ProgressiveOptions`' extract options).

With `Verify`, a redirection member whose header carries an encryption record (Unix or Windows symbolic link,
junction, hard link, file copy) is placed, or passes a test, only when its password check value verifies the
password. No password fails it as `RarFailure::PasswordRequired`, a wrong one as `RarFailure::WrongPassword`, as an
encrypted data member fails; nothing is created. A record without a check value, or with a check value whose
checksum doesn't match, can't verify any password, and a link has no data to check one against: the member is
refused as `RarFailure::EncryptedIntegrity` with `RarIntegrityReason::UnverifiableLinkPassword`, even with the right
password. A progressive session stops at such a member, as it does at a wrong password.

`Verify` checks the password once the member is known to be placed or tested: a member skipped for an existing
target under `Overwrite::Skip` is reported `Skipped(ExistingTarget)`, and a hard link or copy whose target the run
didn't extract fails on its target (`RarPolicyReason::HardLinkTarget`; a progressive session stops with
`UnsafePath`), whatever the password. `VerifyFirst` checks it first, as UnRAR 7.30 does: `unrar x -o- -pwrong` over
links that already exist prints "Incorrect password" and exits 11, and a hard link with a missing target is reported
as the wrong password. Under `VerifyFirst` a password that doesn't verify fails such a member as above
(`WrongPassword`, `PasswordRequired`, `EncryptedIntegrity`/`UnverifiableLinkPassword`) before the overwrite decision
and the target checks; one that verifies goes on to them as usual. Nothing is placed or replaced either way, so this
changes only what is reported. An older file revision is still skipped before anything, on every route. A
`RarSession` test run checks the password first under every mode.

With `PlaceUnverified`, the password isn't checked for such a member (no key is derived): with a wrong password,
with none, or with no check value, the link is placed (or passes a test) and reported as any placed link is,
`RarOutcome::Verified`, with the password evidence `RarPasswordEvidence::Unverified` in its checks, so a caller can
tell it from a verified link (a progressive session reports `MemberOutcome::Verified`/`Tested`, which carries no
password evidence; a caller that set the option knows an encrypted link there went unchecked). Every other link check
still applies: a target that leaves the destination, a hard link or copy of a file the run didn't extract,
protected paths, `replace_placed_links` and the overwrite decision. RAR 4.x symbolic links (whose target is their
encrypted data) and members with data still need their password.

What 7-Zip 26.06 (`7zz`, macOS arm64) does with such archives:

| archive | `x -p<wrong>` | `x` (no `-p`) | `t -p<wrong>` |
|---|---|---|---|
| symlinks and a junction with a check value | links created, exit 0, "Everything is Ok" | same | "ERROR: Wrong password" per link, exit 2 |
| the same without a check value | links created, exit 0 | same | exit 0 |
| hard link and file copy | hard link created; copy "Unsupported Method", exit 2 | same | exit 0 |

So `x` reports no error for an encrypted link under a wrong password or none, and `PlaceUnverified` matches it. `t`
does check a check value it has (a wrong password is an error there, and with no `-p` it asks for one), which
`PlaceUnverified` doesn't mirror: a test passes those links too, with `RarPasswordEvidence::Unverified`.

## 7z wrong passwords: how the member failed

Expand Down
2 changes: 1 addition & 1 deletion docs/persistent-partials.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn start(archive: Vec<u8>, workspace: &Path) -> PartialResult<(ProgressiveSessio
compressed_tar: Default::default(), version_naming: Default::default(),
preexisting_links: Default::default(), refused_link_placeholder: false,
restart_from_first_volume: false,
replace_placed_links: false, keep_broken: false, attempt_continued_members: false, unsupported_filters: Default::default(), salvage_truncated_zip: false, unix_modes: Default::default(), backslashes: Default::default(), damaged_input: Default::default() };
replace_placed_links: false, keep_broken: false, attempt_continued_members: false, encrypted_links: Default::default(), unsupported_filters: Default::default(), salvage_truncated_zip: false, unix_modes: Default::default(), backslashes: Default::default(), damaged_input: Default::default() };
let session = ProgressiveSession::new_partial(
Box::new(CompleteProvider { source: Some(MemorySource { bytes: archive }) }),
ProgressiveOptions::new(extract, "example.rar".into()),
Expand Down
1 change: 1 addition & 0 deletions examples/live_feed/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ fn verify(config: &Config, map: &MemberMap, outputs: &[(usize, u64, PathBuf)]) -
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down
1 change: 1 addition & 0 deletions examples/persistent_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ fn options(dest: &Path) -> ProgressiveOptions {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down
1 change: 1 addition & 0 deletions examples/persistent_holes_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ fn options(dest: &Path, first: &OsString) -> ProgressiveOptions {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down
1 change: 1 addition & 0 deletions examples/zip_small_files_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fn options(dest: &Path, mode: Mode) -> Options {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub(crate) fn main() -> ExitCode {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: damaged,
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down Expand Up @@ -240,6 +241,7 @@ fn listing_options() -> Options {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ pub enum RarPasswordEvidence {
NotEncrypted,
VerifierMatched,
VerifierUnavailable(RarVerifierUnavailable),
/// An encrypted RAR 5.0 redirection placed or tested without its password verifying, as
/// [`crate::extract::EncryptedLinks::PlaceUnverified`] allows: no password was given, its check value rejected
/// the one given, or it has no usable check value.
Unverified,
}

/// Why the encryption record could not verify a password independently.
Expand Down
66 changes: 65 additions & 1 deletion src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,51 @@ pub struct Options {
/// still to come is waited on and one in a hole is `HeaderHole`). Persistent-partial sessions refuse a damaged
/// header whatever this says. 7z and ZIP ignore it.
pub damaged_input: DamagedInput,
/// Whether an encrypted RAR 5.0 redirection member (a symbolic link, junction, hard link or file copy) is placed
/// or tested only when its password check value verifies the password (the default; [`EncryptedLinks::VerifyFirst`]
/// checks it before the overwrite and target decisions, in UnRAR 7.30's order), or whatever the password, as
/// 7-Zip 26.06 `x`/`e` does. See [`EncryptedLinks`].
///
/// Honoured by the whole-archive RAR runners ([`run`], [`run_with_password`], [`run_rar_with_outcomes`], the
/// checked dispatchers), by [`crate::rar5::session::RarSession::extract_selected`] (and its controlled route),
/// and by progressive sessions through [`crate::progressive::ProgressiveOptions`]' extract options. A RarSession
/// test run, which takes no `Options`, reads [`crate::rar5::session::RarSessionOptions::encrypted_links`].
pub encrypted_links: EncryptedLinks,
}

/// What an encrypted RAR 5.0 redirection member needs before it is placed or tested; see
/// [`Options::encrypted_links`].
///
/// `rar a -p` leaves file headers in the clear, so a redirection's target is readable with any password, and a link
/// has no data a wrong password would fail to decrypt: only its encryption record's password check value can tell.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
pub enum EncryptedLinks {
/// Placed only when the member's check value verifies the password, checked once the member is known to be placed
/// or tested (a member skipped for an existing target, or refused for its target, is reported so whatever the
/// password). No password fails the member
/// as [`RarFailure::PasswordRequired`], a wrong one as [`RarFailure::WrongPassword`], and a record with no usable
/// check value as [`RarFailure::EncryptedIntegrity`] with
/// [`crate::error::RarIntegrityReason::UnverifiableLinkPassword`].
#[default]
Verify,
/// As [`Self::Verify`], in UnRAR 7.30's reporting order: the password is checked as soon as the member is reached,
/// before the overwrite decision (an existing target under [`Overwrite::Skip`]) and before a hard link's or copy's
/// target is checked, so a password that doesn't verify is reported as the failure above even for a member that
/// would otherwise be skipped or refused (UnRAR's "Incorrect password", exit 11, where `Verify` reports
/// [`RarSkipReason::ExistingTarget`] or the link target). A password that verifies goes on to those decisions as
/// usual. Nothing is placed or touched either way: only the reported outcome differs. An older file revision is
/// still skipped first, as every route skips one before reading it.
VerifyFirst,
/// As 7-Zip 26.06 `x`/`e` (exit 0, "Everything is Ok"): the password isn't checked for a redirection, so one is
/// placed (or passes a test) with a wrong password, with none, or with no check value to verify it by. It is
/// reported as any placed link is ([`RarOutcome::Verified`]), with the password evidence
/// [`RarPasswordEvidence::Unverified`] (the password isn't checked at all, so a right one reports that too).
/// Every other link check applies as for any link: a target that leaves
/// the destination, a hard link or copy of a file this run didn't extract, protected paths and the overwrite
/// decision. Only RAR 5.0 redirections: a RAR 4.x symbolic link's target is its encrypted data, checked as it
/// decrypts, and members with data still need their password.
PlaceUnverified,
}

/// What a damaged RAR header does to a run; see [`Options::damaged_input`].
Expand Down Expand Up @@ -624,6 +669,7 @@ impl MemberRef<'_> {
/// replace_placed_links: false,
/// keep_broken: false,
/// attempt_continued_members: false,
/// encrypted_links: Default::default(),
/// damaged_input: Default::default(),
/// unsupported_filters: Default::default(),
/// salvage_truncated_zip: false,
Expand Down Expand Up @@ -4292,6 +4338,7 @@ fn rar_read_at(
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down Expand Up @@ -4656,6 +4703,15 @@ impl Run<'_, '_, '_> {
password: std::result::Result<RarPasswordEvidence, RarFailure>,
) -> RunResult<()> {
self.drain()?;
// Options::encrypted_links: VerifyFirst reports a password that doesn't verify before any target decision
let password = match password {
Err(failure) if self.opts.encrypted_links == EncryptedLinks::VerifyFirst => {
let why = link_password_message(&failure);
let cause = self.fail_in_order(&ctx, failure, why)?;
return self.past_link(vol, h, ctx, Some(cause));
}
password => password,
};
let refusal = match &kind {
Ok(kind) => link::refusal_before_place(rel, kind, &self.landing.extracted),
Err(_) => Some(link::HARD_TARGET),
Expand Down Expand Up @@ -4886,11 +4942,18 @@ impl Run<'_, '_, '_> {
}
return self.reports.directory(&ctx);
}
// Options::encrypted_links: a RAR 5.0 redirection placed or tested here needs no password to be given (it is
// checked, or let go, with the link)
let unverified_link = self.opts.encrypted_links == EncryptedLinks::PlaceUnverified
&& h.format == RarFormat::Rar5
&& h.redirection.is_some()
&& self.selection.is_none();
let refuse = if let Some(reason) = h.rar4_unsupported() {
Some((RarFailure::Unsupported(reason), "unsupported RAR4 payload feature"))
} else if let Some(Err(e)) = crypt {
Some((RarFailure::crypt(e, ctx.scope()), "encrypted (password required)"))
} else if h.encrypted
&& !unverified_link
&& match h.format {
RarFormat::Rar4 => self.rar4_password.is_none(),
RarFormat::Rar5 => self.password.is_none() || h.crypt.is_none(),
Expand Down Expand Up @@ -4920,7 +4983,7 @@ impl Run<'_, '_, '_> {
{
// its target is in the clear: an encrypted link is placed only on a password its check value verifies (applied
// once the link is known to be placed or tested: a skipped one stays skipped)
let password = link::rar5_password(h, self.password, ctx.scope());
let password = link::rar5_link_password(h, self.password, ctx.scope(), self.opts.encrypted_links);
return self.rar5_link(vol, h, ctx, &rel, kind, password);
}
if let Some(link) = &h.redirection {
Expand Down Expand Up @@ -6346,6 +6409,7 @@ mod read_once {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
unix_modes: Default::default(),
Expand Down
18 changes: 18 additions & 0 deletions src/extract/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ pub(crate) fn rar5_password(
}
}

/// [`rar5_password`] under [`crate::extract::Options::encrypted_links`]: with
/// [`crate::extract::EncryptedLinks::PlaceUnverified`] the password isn't checked at all (no key is derived), as
/// 7-Zip 26.06 doesn't check it, and an encrypted link passes with the evidence
/// [`crate::error::RarPasswordEvidence::Unverified`]. Only the password is let go: every other link check applies.
pub(crate) fn rar5_link_password(
header: &crate::rar5::FileHeader,
password: Option<&str>,
scope: crate::error::RarScope,
links: crate::extract::EncryptedLinks,
) -> Result<crate::error::RarPasswordEvidence, crate::error::RarFailure> {
match links {
crate::extract::EncryptedLinks::PlaceUnverified if header.encrypted => {
Ok(crate::error::RarPasswordEvidence::Unverified)
}
_ => rar5_password(header, password, scope),
}
}

/// Why these encryption parameters can't verify a password, or None when their check value can: there is one,
/// and its checksum matches. Checked before any key is derived.
pub(crate) fn rar5_unverifiable(
Expand Down
1 change: 1 addition & 0 deletions src/progressive/growing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ impl RangeSource for GrowingFileSource {
/// replace_placed_links: false,
/// keep_broken: false,
/// attempt_continued_members: false,
/// encrypted_links: Default::default(),
/// damaged_input: Default::default(),
/// unsupported_filters: Default::default(),
/// salvage_truncated_zip: false,
Expand Down
1 change: 1 addition & 0 deletions src/progressive/output/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn setup(dir: &Path) -> OutputContext {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down
1 change: 1 addition & 0 deletions src/progressive/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ mod tests {
replace_placed_links: false,
keep_broken: false,
attempt_continued_members: false,
encrypted_links: Default::default(),
damaged_input: Default::default(),
unsupported_filters: Default::default(),
salvage_truncated_zip: false,
Expand Down
Loading
Loading