Repository navigation
[COMPRESS-639] Key the entry metadata of ZipArchiveOutputStream by identity - #826
Open
sharanggupta wants to merge 2 commits into
Open
sharanggupta wants to merge 2 commits into
sharanggupta wants to merge 2 commits into
Conversation
…entity ZipArchiveOutputStream looked up the local header offset of each entry in a HashMap keyed by ZipArchiveEntry, whose equals(Object) depends on fields that change while an entry is written. Equal entries, such as the ones ParallelScatterZipCreator adds for the same name, then shared one map entry: the central directory pointed both at the same local header, or close() threw a NullPointerException. Use an IdentityHashMap and enable the test that was disabled for COMPRESS-639.
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.
COMPRESS-639
What
ZipArchiveOutputStreamkeeps the local header offset of each entry in aHashMapkeyed by theZipArchiveEntry, and looks it up when it writes the central directory.ZipArchiveEntry.hashCode()only uses the name, butequals(Object)compares the times, sizes, CRC, extra fields and more, and some of these change while an entry is written. So entries with the same name, time, size and CRC, such as the entries thatParallelScatterZipCreatoradds in the issue, can share one map entry:putreplaces the offset of the first, and both central directory records point to the second local file header. The archive silently loses the first entry.Zip64Mode.Always, the lookup of the other entry finds nothing, andclose()throws theNullPointerExceptionfrom the issue.How
The map is now an
IdentityHashMap. Each entry is put and looked up with the sameZipArchiveEntryinstance, so every entry keeps its own offset, whateverequals(Object)says.Tests
ParallelScatterZipCreatorTest.sameZipArchiveEntryNullPointerException, which was disabled for COMPRESS-639, is enabled. It now also reads the archive back and checks that the 100 entries have 100 different local header offsets. It fails onmasterwith theNullPointerException.ZipArchiveOutputStreamTest.testEqualEntriesKeepTheirOwnLocalHeaderswrites two equalSTOREDentries and checks withZipFilethat the first entry's local header is at offset 0 and the second one's right after the first entry's data. Onmaster, both point to the second local header.changes.xmlhas an entry.mvnandmvn changes:changes-validate -DfailOnError=truepass locally on JDK 17.Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.