Skip to content

fix(sevenz): normalize backslash in entry names before validation#377

Merged
bug-ops merged 1 commit into
mainfrom
376-365-path-norm
Jun 29, 2026
Merged

fix(sevenz): normalize backslash in entry names before validation#377
bug-ops merged 1 commit into
mainfrom
376-365-path-norm

Conversation

@bug-ops

@bug-ops bug-ops commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds formats::common::normalize_entry_name helper that converts \ to / in 7z entry names before PathBuf construction
  • Applies normalization in all three 7z entry-name sites: extract pre-validation loop, extract callback, and list/verify path (inspection/list.rs)
  • Documents the caller contract in SafePath::validate doc comment
  • ZIP and TAR are intentionally unaffected

Background

When #375 switched the 7z handler from decompress_with_extract_fn to ArchiveReader::for_each_entries, the upstream safe_join check (which did replace('\\', '/')) was bypassed. On Unix, a \-containing entry name like ..\\..\x becomes a single Normal path component in PathBuf, silently passing traversal detection. The extract path would accept the entry; the list/verify path had the same gap.

Test plan

  • test_7z_backslash_entry_rejected — asserts ..\\..\\xPathTraversal error on all platforms
  • cargo nextest run --workspace --all-features --exclude exarch-python --exclude exarch-node — 932 tests pass
  • cargo test --doc -p exarch-core --all-features — 98 doc-tests pass
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — clean
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --workspace — clean

Closes #376
Closes #365

…, #365)

On Unix, entry names containing `\` (e.g. `..\..\\x`) were treated as a
single path component by std's PathBuf, bypassing traversal detection in
SafePath::validate. The upstream sevenz-rust2 safe_join that previously
rejected these was removed in #375 when switching to for_each_entries.

Add `formats::common::normalize_entry_name` that replaces `\` with `/`
before PathBuf construction. Apply it in all three 7z entry-name sites:
the extraction pre-validation loop, the extraction callback, and the
list/verify path in inspection/list.rs. This ensures extract, list, and
verify all agree on traversal detection.

ZIP is unaffected (zip crate handles Windows paths internally via
enclosed_name). TAR is correctly left un-normalized (`\` is a legal
Unix filename character in TAR).

Closes #376
Closes #365
@github-actions github-actions Bot added core Changes to exarch-core docs Documentation labels Jun 29, 2026
@bug-ops bug-ops enabled auto-merge (squash) June 29, 2026 17:59
@bug-ops bug-ops merged commit 6349fb1 into main Jun 29, 2026
24 checks passed
@bug-ops bug-ops deleted the 376-365-path-norm branch June 29, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to exarch-core docs Documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sevenz): normalize/reject embedded backslash in 7z entry names feat(core): align absolute-path stripping across zip/tar/7z format handlers

1 participant