Repository: commons-compress Updated Branches: refs/heads/master 469752132 -> 8a6bb5623
COMPRESS-394 zip 2.0 is required when DEFLATE is used Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/8a6bb562 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/8a6bb562 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/8a6bb562 Branch: refs/heads/master Commit: 8a6bb5623e92f3d636969488a04a516cd0ae7f36 Parents: 4697521 Author: Stefan Bodewig <bode...@apache.org> Authored: Tue May 16 18:51:16 2017 +0200 Committer: Stefan Bodewig <bode...@apache.org> Committed: Tue May 16 18:51:16 2017 +0200 ---------------------------------------------------------------------- .../archivers/zip/ZipArchiveOutputStream.java | 14 +++++++++----- .../commons/compress/archivers/zip/ZipConstants.java | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/8a6bb562/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java index 2b3af25..5ad6742 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java @@ -41,6 +41,7 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.utils.IOUtils; import static org.apache.commons.compress.archivers.zip.ZipConstants.DATA_DESCRIPTOR_MIN_VERSION; +import static org.apache.commons.compress.archivers.zip.ZipConstants.DEFLATE_MIN_VERSION; import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD; import static org.apache.commons.compress.archivers.zip.ZipConstants.INITIAL_VERSION; import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT; @@ -695,7 +696,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { // do some cleanup: // * rewrite version needed to extract channel.position(entry.localDataStart - 5 * SHORT); - writeOut(ZipShort.getBytes(INITIAL_VERSION)); + writeOut(ZipShort.getBytes(versionNeededToExtractMethod(entry.entry.getMethod()))); // * remove ZIP64 extra so it doesn't get written // to the central directory @@ -1071,7 +1072,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { final int zipMethod = ze.getMethod(); if (phased && !isZip64Required(entry.entry, zip64Mode)){ - putShort(INITIAL_VERSION, buf, LFH_VERSION_NEEDED_OFFSET); + putShort(versionNeededToExtractMethod(zipMethod), buf, LFH_VERSION_NEEDED_OFFSET); } else { putShort(versionNeededToExtract(zipMethod, hasZip64Extra(ze)), buf, LFH_VERSION_NEEDED_OFFSET); } @@ -1483,15 +1484,18 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { } // requires version 2 as we are going to store length info // in the data descriptor - return (isDeflatedToOutputStream(zipMethod)) ? - DATA_DESCRIPTOR_MIN_VERSION : - INITIAL_VERSION; + return isDeflatedToOutputStream(zipMethod) + ? DATA_DESCRIPTOR_MIN_VERSION + : versionNeededToExtractMethod(zipMethod); } private boolean isDeflatedToOutputStream(final int zipMethod) { return zipMethod == DEFLATED && channel == null; } + private int versionNeededToExtractMethod(int zipMethod) { + return zipMethod == DEFLATED ? DEFLATE_MIN_VERSION : INITIAL_VERSION; + } /** * Creates a new zip entry taking some information from the given http://git-wip-us.apache.org/repos/asf/commons-compress/blob/8a6bb562/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java index b6e2d45..23f04a8 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java @@ -40,6 +40,12 @@ final class ZipConstants { /** Initial ZIP specification version */ static final int INITIAL_VERSION = 10; + /** + * ZIP specification version that introduced DEFLATE compression method. + * @since 1.15 + */ + static final int DEFLATE_MIN_VERSION = 20; + /** ZIP specification version that introduced data descriptor method */ static final int DATA_DESCRIPTOR_MIN_VERSION = 20;