Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support preamble garbage in ZipArchiveInputStream #471

Merged

Conversation

kvr000
Copy link
Contributor

@kvr000 kvr000 commented Jan 27, 2024

zip can ignore any garbage at the beginning of file up to certain size. This is supported in ZipFile but not in ZipArchiveInputStream. This PR fixes that, including correct check for empty archive.

@kvr000 kvr000 force-pushed the feature/zip-skip-preamble-garbage branch 2 times, most recently from ee3aa52 to 59777a1 Compare January 27, 2024 20:44
@codecov-commenter
Copy link

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (86d2232) 80.64% compared to head (59777a1) 80.63%.
Report is 5 commits behind head on master.

Files Patch % Lines
.../compress/archivers/zip/ZipArchiveInputStream.java 87.80% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #471      +/-   ##
============================================
- Coverage     80.64%   80.63%   -0.02%     
- Complexity     6777     6781       +4     
============================================
  Files           348      348              
  Lines         24901    24926      +25     
  Branches       4022     4029       +7     
============================================
+ Hits          20082    20098      +16     
- Misses         3298     3304       +6     
- Partials       1521     1524       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@garydgregory
Copy link
Member

Hello @kvr000
Is this documented anywhere? PREAMBLE_GARBAGE_MAX_SIZE?

@kvr000
Copy link
Contributor Author

kvr000 commented Jan 28, 2024

Hello @kvr000 Is this documented anywhere? PREAMBLE_GARBAGE_MAX_SIZE?

I haven't found "official" support for skipping the garbage in the specification. zip program and ZipFile from apache compress naturally do it because they go backward from the end of central directory, though zip eventually prints a warning about garbage at the beginning.

I used 4096 as it should be enough for typical case when the program execution is added at the beginning: #!/usr/bin/env -S whatever with the arguments such as java -Xmx32M -jar

@garydgregory garydgregory merged commit 7d2fde7 into apache:master Jan 28, 2024
15 checks passed
@garydgregory
Copy link
Member

@kvr000
Thank you for the clarification; merged.

garydgregory pushed a commit that referenced this pull request Feb 23, 2024
…486)

Fix regression error in case when getNextEntry() method is invoked on
empty file (zero size) to get first entry. Till version 1.25.0, null
value was returned (like is done in standard java ZipInputStream too).
The regression was caused by implementing 'Support preamble garbage
in ZipArchiveInputStream' feature (PR 471).
 - #471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants