Conversation
Noticed when attempting to unpack a python `.whl` wheel file;
They're just renamed .zip's, and usually work OK, but there are casess
where the first file in the `.whl` archive is zero bytes, and that
causes `file -z` to error:
```bash
❯ file -zL tests/test-1.23.zip
tests/test-1.23.zip: ERROR:[gzip: ] (data)
❯ file tests/test-1.23.zip
tests/test-1.23.zip: Zip archive data, made by v2.3 UNIX, extract using at least v1.0, last modified Oct 28 2006 14:38:44, uncompressed size 0, method=store
❯ unzip -l tests/test-1.23.zip
Archive: tests/test-1.23.zip
Length Date Time Name
--------- ---------- ----- ----
0 2006-10-28 14:38 1/2/3
0 2006-10-28 14:38 a/b
0 2006-10-28 14:38 foobar
--------- -------
0 3 files
```
This means we were not using `file` magic for any archive that started
with a zero-length file (or directory) entry.
Add a fallback when the magic test fails in this case, and add a test to
cover it.
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where file -z fails to detect archives when the first entry is zero-length, and adds test coverage for this scenario. Python wheel files commonly have zero-byte entries at the beginning, which previously caused magic detection to fail.
Key changes:
- Add fallback logic to retry
filecommand without-zflag when ERROR is detected - Add test case with a
.whlfile containing zero-length entries - Move output reading and processing after error checking
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dtrx/dtrx.py | Adds error detection and fallback logic to retry without -z flag when file command encounters ERROR on zero-length archive entries |
| tests/tests.yml | Adds test case for .whl files with zero-length entries |
| tests/test-1.23.whl | Adds test fixture containing a wheel archive with zero-length entries |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
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.
Noticed when attempting to unpack a python
.whlwheel file;They're just renamed .zip's, and usually work OK, but there are casess
where the first file in the
.whlarchive is zero bytes, and thatcauses
file -zto error:❯ file -zL tests/test-1.23.zip tests/test-1.23.zip: ERROR:[gzip: ] (data) ❯ file tests/test-1.23.zip tests/test-1.23.zip: Zip archive data, made by v2.3 UNIX, extract using at least v1.0, last modified Oct 28 2006 14:38:44, uncompressed size 0, method=store ❯ unzip -l tests/test-1.23.zip Archive: tests/test-1.23.zip Length Date Time Name --------- ---------- ----- ---- 0 2006-10-28 14:38 1/2/3 0 2006-10-28 14:38 a/b 0 2006-10-28 14:38 foobar --------- ------- 0 3 filesThis means we were not using
filemagic for any archive that startedwith a zero-length file (or directory) entry.
Add a fallback when the magic test fails in this case, and add a test to
cover it.