-
Notifications
You must be signed in to change notification settings - Fork 49
Fix use of a mismatching unicode path extra field in zip unarchiving #167
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
|
||
import org.apache.commons.compress.archivers.zip.UnicodePathExtraField; | ||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; | ||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; | ||
|
||
public class GenerateZips { | ||
|
||
private static void generate(String outfilename, boolean languageEncodingFlag) { | ||
try { | ||
ZipArchiveOutputStream zs = new ZipArchiveOutputStream(new File(outfilename)); | ||
zs.setUseLanguageEncodingFlag(languageEncodingFlag); | ||
zs.setMethod(ZipArchiveOutputStream.STORED); | ||
ZipArchiveEntry ze = new ZipArchiveEntry("nameonly-name"); | ||
ze.setTime(0); | ||
zs.putArchiveEntry(ze); | ||
//zs.write(nothing); | ||
zs.closeArchiveEntry(); | ||
ze = new ZipArchiveEntry("goodextra-name"); | ||
ze.setTime(0); | ||
ze.addExtraField(new UnicodePathExtraField("goodextra-extra", "goodextra-name".getBytes(Charset.forName("UTF-8")))); | ||
zs.putArchiveEntry(ze); | ||
//zs.write(nothing); | ||
zs.closeArchiveEntry(); | ||
ze = new ZipArchiveEntry("badextra-name"); | ||
ze.setTime(0); | ||
ze.addExtraField(new UnicodePathExtraField("badextra-extra", "bogus".getBytes(Charset.forName("UTF-8")))); | ||
zs.putArchiveEntry(ze); | ||
//zs.write(nothing); | ||
zs.closeArchiveEntry(); | ||
zs.finish(); | ||
zs.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
generate("efsclear.zip", false); | ||
// with the flag set, decoders tend to not look at the extra field | ||
generate("efsset.zip", true); | ||
System.out.println("done"); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Test ZIP Files for Unicode Path Extra Field | ||
|
||
These files are used to test for proper use of Unicode Path extra fields ([zip specification §4.6.9](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)) when unarchiving zip archives. | ||
|
||
Both contain three empty files, one without a Unicode Path extra field, one with a good extra field (CRC matches the header file name), one with a stale extra field (mismatched CRC). By using different values in the header file name and the Unicode path, it can be distinguished which one was used. A compliant unarchiver will use the names marked in bold. | ||
|
||
File name in header | CRC | Unicode Path | ||
--------------------|-----------------------|-------------------- | ||
**nameonly-name** | | ||
goodextra-name | CRC("goodextra-name") | **goodextra-extra** | ||
**badextra-name** | CRC("bogus") | badextra-extra | ||
|
||
The difference between the two archives is whether the Language Encoding Flag (EFS) is set, which indicates that the header file names are already in UTF-8. The specification is not explicit about which one wins when both the flag is set and a Unicode Path extra field is present (it only says archivers shouldn’t do that). In practice, all unarchivers I have seen (including Apache Commons Compress used by Plexus-Archiver) ignore the extra field when the flag is set, which is why only _efsclear.zip_ is useful for testing. | ||
|
||
The archives were created by the included _GenerateZips.java_ using Commons Compress. |
Binary file not shown.
Binary file not shown.
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.
Uh oh!
There was an error while loading. Please reload this page.