fix: skip data reads on directory entries for RAR archives#161
Merged
Conversation
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
caba808 to
9587bc3
Compare
Coverage Report for CI Build 24834523391Coverage increased (+0.5%) to 77.628%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ARCHIVE_FAILEDwith "Can't decompress an entry marked as a directory" whenarchive_read_data_blockis called on a directory entry (other formats just returnARCHIVE_EOF). Our extractors called it unconditionally, so any RAR with directory entries failed extraction — even after files had already been written to disk.libarchive_entry_is_dirhelper (readsstat.st_modeagainst POSIXS_IFMT/S_IFDIRso it stays Windows-safe, sincelibc::S_IFDIRisn't exposed there) and gate the data-read step on it inuncompress_archive_with_encoding,uncompress_archive_file_with_encoding(returnsOk(0)for dir paths), andArchiveIterator::next_data_chunk(returnsEndOfEntry).current_is_diris cached onStartOfEntryso per-chunk reads don't re-dereferencearchive_entry_stat.Closes #131.
Test plan
tests/fixtures/tree.rar(generated withrar -ma5, mirrorstree.tar) covering both file and directory entries.tree.rarbefore the fix with the reported error.uncompress_rar_to_dir,get_a_file_from_rar,iterate_rar_entries.cargo test --features tokio_support,futures_support— 56 integration tests + 14 doc tests pass, no regressions.