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
14 changes: 12 additions & 2 deletions .github/workflows/prepare-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,18 @@ jobs:
if: runner.os == 'Windows'
shell: pwsh
run: |
$bundle = 'target/${{ matrix.rust_target }}/release'
foreach ($f in @("$bundle/maxrar.exe") + (Get-ChildItem "$bundle/bundle/nsis/*.exe").FullName + 'target/explorer-menu/maxrar_shell.dll' + 'target/explorer-menu/maxrar-explorer-menu.msix') {
$setup = (Get-ChildItem 'target/${{ matrix.rust_target }}/release/bundle/nsis/*.exe').FullName
if (@($setup).Count -ne 1) { throw "Expected one NSIS installer; found $(@($setup).Count)" }
# Check the files users actually install: unpack the installer and verify what is inside.
$unpacked = Join-Path $env:RUNNER_TEMP 'signed-installer'
& "$env:ProgramFiles\7-Zip\7z.exe" x -y "-o$unpacked" $setup | Out-Null
if ($LASTEXITCODE) { throw "Could not unpack $setup" }
$inside = foreach ($name in 'maxrar.exe', 'maxrar_shell.dll') {
$found = @(Get-ChildItem $unpacked -Recurse -File -Filter $name)
if ($found.Count -eq 0) { throw "$name is missing from the installer" }
$found.FullName
}
foreach ($f in @($setup) + $inside + 'target/explorer-menu/maxrar_shell.dll' + 'target/explorer-menu/maxrar-explorer-menu.msix') {
$sig = Get-AuthenticodeSignature -LiteralPath $f
if ($sig.Status -ne 'Valid') { throw "$f signature: $($sig.Status)" }
Write-Output "$([IO.Path]::GetFileName($f)): $($sig.SignerCertificate.Subject)"
Expand Down
27 changes: 26 additions & 1 deletion crates/wonrar-core/src/sevenz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ pub(super) fn inspect(path: &Path, secret: Option<&str>) -> Result<ArchiveInfo>
})
}

struct Counted<'a> {
inner: &'a mut dyn Read,
n: u64,
}

impl Read for Counted<'_> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let n = self.inner.read(buf)?;
self.n += n as u64;
Ok(n)
}
}

/// Map callback entries back to their central inventory IDs without relying on names.
/// The library passes references to its stable `archive.files` allocation.
fn traverse(
Expand Down Expand Up @@ -157,7 +170,19 @@ fn traverse(
.get(&(entry as *const ArchiveEntry as usize))
.copied()
.ok_or_else(|| sevenz_rust2::Error::Other("7z entry identity unavailable".into()))?;
match each(id, entry, stream) {
// The library checks a CRC only once the declared size has been read, so
// a wrong key whose garbage stream ends early would otherwise pass.
let mut counted = Counted { inner: stream, n: 0 };
let outcome = each(id, entry, &mut counted).and_then(|()| {
if entry.is_directory || counted.n == entry.size {
Ok(())
} else {
Err(invalid(
"Decoded size does not match the archive. The password may be wrong or the archive damaged.",
))
}
});
match outcome {
Ok(()) => Ok(true),
Err(e) => {
original = Some(e);
Expand Down
26 changes: 26 additions & 0 deletions crates/wonrar-core/tests/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,32 @@ fn sevenz_roundtrip_with_password_and_explicit_read_only_edits() {
assert_eq!(fs::read(&a).unwrap(), original);
}

#[test]
fn sevenz_wrong_passwords_never_test_or_extract() {
let t = tempfile::tempdir().unwrap();
let source = t.path().join("hello.txt");
fs::write(&source, "héllo sevenz").unwrap();
let a = t.path().join("a.7z");
create_with_password(&a, &[source], &cancel(), &|_| {}, Some("password")).unwrap();
// A wrong key can decode to a short garbage stream; every attempt must fail.
for i in 0..3000 {
let wrong = format!("wrong-{i}");
assert!(test_with_password(&a, &cancel(), &|_| {}, Some(&wrong)).is_err());
let dest = t.path().join(format!("out-{i}"));
let p = plan_with_password(
&a,
&dest,
&[],
ConflictPolicy::Skip,
Limits::default(),
Some(&wrong),
)
.unwrap();
assert!(extract_with_password(&p, &cancel(), &|_| {}, Some(&wrong)).is_err());
assert!(!dest.join("hello.txt").exists());
}
}

#[test]
fn sevenz_traversal_and_symlink_metadata_are_blocked() {
use sevenz_rust2::{ArchiveEntry, ArchiveWriter};
Expand Down
Loading