Skip to content

Conversation

@noahp
Copy link
Member

@noahp noahp commented Nov 26, 2025

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:

❯ 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.

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.
Copilot AI review requested due to automatic review settings November 26, 2025 17:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 file command without -z flag when ERROR is detected
  • Add test case with a .whl file 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.

@noahp noahp merged commit 453d041 into master Dec 1, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants