From 51c2e059ba5e4d1892f30b96fbfcd8866d41987d Mon Sep 17 00:00:00 2001 From: Danny Deschenes <54910444+ddeschenes-1@users.noreply.github.com> Date: Fri, 13 Dec 2024 20:57:03 -0500 Subject: [PATCH 1/4] (doc) fix gzip streams incorrect MTIME value which is already in seconds (#624) --- .../compress/compressors/gzip/GzipCompressorInputStream.java | 2 +- .../compress/compressors/gzip/GzipCompressorOutputStream.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java index 8e05bdebe67..7f5d3cd09d4 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java @@ -227,7 +227,7 @@ private boolean init(final boolean isFirstMember) throws IOException { throw new IOException("Reserved flags are set in the .gz header"); } - parameters.setModificationTime(ByteUtils.fromLittleEndian(inData, 4) * 1000); + parameters.setModificationTime(ByteUtils.fromLittleEndian(inData, 4)); switch (inData.readUnsignedByte()) { // extra flags case 2: parameters.setCompressionLevel(Deflater.BEST_COMPRESSION); diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java index 007f7428ddd..4eaf663dadd 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java @@ -178,7 +178,7 @@ private void writeHeader(final GzipParameters parameters) throws IOException { buffer.putShort((short) GZIPInputStream.GZIP_MAGIC); buffer.put((byte) Deflater.DEFLATED); // compression method (8: deflate) buffer.put((byte) ((extra != null ? FEXTRA : 0) | (fileName != null ? FNAME : 0) | (comment != null ? FCOMMENT : 0))); // flags - buffer.putInt((int) (parameters.getModificationTime() / 1000)); + buffer.putInt((int) (parameters.getModificationTime())); // extra flags final int compressionLevel = parameters.getCompressionLevel(); if (compressionLevel == Deflater.BEST_COMPRESSION) { From 90287b2bb138daf3e44bd7f89173dd9fb760eb3e Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Fri, 13 Dec 2024 21:14:23 -0500 Subject: [PATCH 2/4] GzipCompressorInputStream reads the modification time (MTIME) and stores its value incorrectly multiplied by 1,000 GzipCompressorInputStream writes the modification time (MTIME) the value incorrectly divided by 1,000 --- src/changes/changes.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2ea89793afe..9bce65f4dd1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -56,6 +56,7 @@ The type attribute can be add,update,fix,remove. Update outdated links in ZipMethod Javadoc #619. Deprecate ZipUtil.signedByteToUnsignedInt(byte) in favor of Byte.toUnsignedInt(byte). ZipArchiveOutputStream.close() does not close its underlying output stream. + ZipArchiveOutputStream.close() does not close its underlying output stream. Add GzipParameters.getModificationInstant(). Add GzipParameters.setModificationInstant(Instant). @@ -65,7 +66,8 @@ The type attribute can be add,update,fix,remove. Add support for gzip extra subfields, see GzipParameters.setExtra(HeaderExtraField) #604. Add CompressFilterOutputStream and refactor to use. Add ZipFile.stream(). - ArchiveOutputStream.isClosed() is now public, was protected. + GzipCompressorInputStream reads the modification time (MTIME) and stores its value incorrectly multiplied by 1,000. + GzipCompressorInputStream writes the modification time (MTIME) the value incorrectly divided by 1,000. Bump org.apache.commons:commons-parent from 72 to 78 #563, #567, #574, #582, #587, #595. Bump com.github.luben:zstd-jni from 1.5.6-4 to 1.5.6-8 #565, #578, #601, #616. From 2e401e76a35b2bd4ba3448130e0cec951f7f1c42 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Fri, 13 Dec 2024 21:18:48 -0500 Subject: [PATCH 3/4] Use GzipParameters.getModificationInstant() to avoid scale confusion --- .../compress/compressors/gzip/GzipCompressorOutputStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java index 4eaf663dadd..5fc64ed8d0d 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java @@ -178,7 +178,7 @@ private void writeHeader(final GzipParameters parameters) throws IOException { buffer.putShort((short) GZIPInputStream.GZIP_MAGIC); buffer.put((byte) Deflater.DEFLATED); // compression method (8: deflate) buffer.put((byte) ((extra != null ? FEXTRA : 0) | (fileName != null ? FNAME : 0) | (comment != null ? FCOMMENT : 0))); // flags - buffer.putInt((int) (parameters.getModificationTime())); + buffer.putInt((int) (parameters.getModificationInstant().getEpochSecond())); // extra flags final int compressionLevel = parameters.getCompressionLevel(); if (compressionLevel == Deflater.BEST_COMPRESSION) { From 028090d3999bb6ad7da9dfd5b8e29dba1ac5b9ee Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Fri, 13 Dec 2024 21:27:54 -0500 Subject: [PATCH 4/4] Git ignore /.java-version --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c57d236b9dd..b8bd17e8221 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ target *~ /.externalToolBuilders/ /maven-eclipse.xml +/.java-version