You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/08/14 14:06:08 UTC

(commons-compress) branch master updated (c0a114e03 -> a8f852488)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


    from c0a114e03 Bump github/codeql-action from 3.25.15 to 3.26.0 (#557)
     new d8a38b20c [COMPRESS-686] Compression into BZip2 format has unexpected end of file
     new a8f852488 Remove whitespace

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../bzip2/BZip2CompressorInputStream.java          | 15 ----
 .../compressors/bzip2/Compress686Test.java         | 85 ++++++++++++++++++++++
 2 files changed, 85 insertions(+), 15 deletions(-)
 create mode 100644 src/test/java/org/apache/commons/compress/compressors/bzip2/Compress686Test.java


(commons-compress) 02/02: Remove whitespace

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit a8f8524887e795be5fa8028e93072fe93771103b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 14 10:05:40 2024 -0400

    Remove whitespace
---
 .../compressors/bzip2/BZip2CompressorInputStream.java     | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
index fe5dc5c48..82190e4b3 100644
--- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
@@ -232,21 +232,13 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements
     private int storedBlockCRC, storedCombinedCRC;
     private int computedCombinedCRC;
     private int su_count;
-
     private int su_ch2;
-
     private int su_chPrev;
-
     private int su_i2;
-
     private int su_j2;
-
     private int su_rNToGo;
-
     private int su_rTPos;
-
     private int su_tPos;
-
     private char su_z;
 
     /**
@@ -278,7 +270,6 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements
     public BZip2CompressorInputStream(final InputStream in, final boolean decompressConcatenated) throws IOException {
         this.bin = new BitInputStream(in == System.in ? CloseShieldInputStream.wrap(in) : in, ByteOrder.BIG_ENDIAN);
         this.decompressConcatenated = decompressConcatenated;
-
         init(true);
         initBlock();
     }
@@ -300,11 +291,9 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements
         this.storedCombinedCRC = bsGetInt(bin);
         this.currentState = EOF;
         this.data = null;
-
         if (this.storedCombinedCRC != this.computedCombinedCRC) {
             throw new IOException("BZip2 CRC error");
         }
-
         // Look for the next .bz2 stream if decompressing
         // concatenated files.
         return !decompressConcatenated || !init(false);
@@ -341,17 +330,14 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements
 
     private void endBlock() throws IOException {
         final int computedBlockCRC = this.crc.getValue();
-
         // A bad CRC is considered a fatal error.
         if (this.storedBlockCRC != computedBlockCRC) {
             // make next blocks readable without error
             // (repair feature, not yet documented, not tested)
             this.computedCombinedCRC = this.storedCombinedCRC << 1 | this.storedCombinedCRC >>> 31;
             this.computedCombinedCRC ^= this.storedBlockCRC;
-
             throw new IOException("BZip2 CRC error");
         }
-
         this.computedCombinedCRC = this.computedCombinedCRC << 1 | this.computedCombinedCRC >>> 31;
         this.computedCombinedCRC ^= computedBlockCRC;
     }
@@ -360,7 +346,6 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements
         final BitInputStream bin = this.bin;
         this.origPtr = bsR(bin, 24);
         recvDecodingTables();
-
         final Data dataShadow = this.data;
         final byte[] ll8 = dataShadow.ll8;
         final int[] unzftab = dataShadow.unzftab;


(commons-compress) 01/02: [COMPRESS-686] Compression into BZip2 format has unexpected end of file

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit d8a38b20c1adb2f7819b2029ead6ff86e03a0471
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 14 09:36:03 2024 -0400

    [COMPRESS-686] Compression into BZip2 format has unexpected end of file
    
    Add test and TODO
---
 .../compressors/bzip2/Compress686Test.java         | 85 ++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/src/test/java/org/apache/commons/compress/compressors/bzip2/Compress686Test.java b/src/test/java/org/apache/commons/compress/compressors/bzip2/Compress686Test.java
new file mode 100644
index 000000000..39c154b8a
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/compressors/bzip2/Compress686Test.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.commons.compress.compressors.bzip2;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/**
+ * Tests COMPRESS-686.
+ */
+public class Compress686Test {
+
+    @TempDir
+    private Path tempDir;
+
+    private Path compressFile(final Path file, final boolean bufferOutput) throws IOException {
+        final Path newFile = tempDir.resolve(file.getFileName().toString() + ".bz2");
+        try (InputStream in = Files.newInputStream(file);
+                BZip2CompressorOutputStream bzOut = new BZip2CompressorOutputStream(newOutputStream(newFile, bufferOutput))) {
+            IOUtils.copy(in, bzOut);
+        }
+        return newFile;
+    }
+
+    private Path decompressBzip2File(final Path file) throws IOException {
+        final Path decompressedFile = Paths.get(file.getParent().toString(), file.getFileName().toString() + ".decompressed");
+        try (BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(Files.newInputStream(file));
+                OutputStream outputStream = new FileOutputStream(decompressedFile.toFile())) {
+            IOUtils.copy(bzIn, outputStream);
+        }
+        return decompressedFile;
+    }
+
+    private OutputStream newOutputStream(final Path newFile, final boolean bufferOutput) throws IOException {
+        final OutputStream outputStream = Files.newOutputStream(newFile);
+        return bufferOutput ? new BufferedOutputStream(outputStream) : outputStream;
+    }
+
+    @ParameterizedTest
+    // TODO
+    // @ValueSource(booleans = { true, false })
+    @ValueSource(booleans = { false })
+    public void testRoundtrip(final boolean bufferOutput) throws Exception {
+        final Path file = tempDir.resolve("test.txt");
+        final String contents = "random contents";
+        try (Writer w = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
+            IOUtils.write(contents, w);
+        }
+        final Path compressedFile = compressFile(file, bufferOutput);
+        decompressBzip2File(compressedFile);
+        assertEquals(contents, IOUtils.toString(file.toUri(), StandardCharsets.UTF_8));
+    }
+}