Skip to content

fix: skip data reads on directory entries for RAR archives#161

Merged
otavio merged 1 commit intomasterfrom
fix-rar-directory-entries
Apr 23, 2026
Merged

fix: skip data reads on directory entries for RAR archives#161
otavio merged 1 commit intomasterfrom
fix-rar-directory-entries

Conversation

@otavio
Copy link
Copy Markdown
Member

@otavio otavio commented Apr 23, 2026

Summary

  • libarchive's RAR reader returns ARCHIVE_FAILED with "Can't decompress an entry marked as a directory" when archive_read_data_block is called on a directory entry (other formats just return ARCHIVE_EOF). Our extractors called it unconditionally, so any RAR with directory entries failed extraction — even after files had already been written to disk.
  • Added a libarchive_entry_is_dir helper (reads stat.st_mode against POSIX S_IFMT/S_IFDIR so it stays Windows-safe, since libc::S_IFDIR isn't exposed there) and gate the data-read step on it in uncompress_archive_with_encoding, uncompress_archive_file_with_encoding (returns Ok(0) for dir paths), and ArchiveIterator::next_data_chunk (returns EndOfEntry).
  • For the iterator, current_is_dir is cached on StartOfEntry so per-chunk reads don't re-dereference archive_entry_stat.

Closes #131.

Test plan

  • New tests/fixtures/tree.rar (generated with rar -ma5, mirrors tree.tar) covering both file and directory entries.
  • Confirmed the existing extraction path fails on tree.rar before the fix with the reported error.
  • New integration tests pass after the fix: uncompress_rar_to_dir, get_a_file_from_rar, iterate_rar_entries.
  • Full suite green: cargo test --features tokio_support,futures_support — 56 integration tests + 14 doc tests pass, no regressions.

libarchive's RAR reader returns ARCHIVE_FAILED on `archive_read_data_block`
for directory entries, causing every RAR containing directories to error
with "Can't decompress an entry marked as a directory". Skip the data-read
step for directory entries in `uncompress_archive`, `uncompress_archive_file`,
and `ArchiveIterator`.

Closes #131
@otavio otavio force-pushed the fix-rar-directory-entries branch from caba808 to 9587bc3 Compare April 23, 2026 12:12
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 23, 2026

Coverage Report for CI Build 24834523391

Coverage increased (+0.5%) to 77.628%

Details

  • Coverage increased (+0.5%) from the base build.
  • Patch coverage: 2 uncovered changes across 2 files (57 of 59 lines covered, 96.61%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
src/lib.rs 10 9 90.0%
tests/integration_test.rs 44 43 97.73%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 2454
Covered Lines: 1905
Line Coverage: 77.63%
Coverage Strength: 84.73 hits per line

💛 - Coveralls

@otavio otavio merged commit b868768 into master Apr 23, 2026
14 checks passed
@otavio otavio deleted the fix-rar-directory-entries branch April 23, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Rar archive always errors on extraction

2 participants