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 29c2703bbc1c879329f187b47013bb8e99449326
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Aug 15 09:33:49 2024 -0400

    [COMPRESS-686] Compression into BZip2 format has unexpected end of file
    when using a BufferedOutputStream
---
 src/changes/changes.xml                                           | 1 +
 .../compress/compressors/bzip2/BZip2CompressorOutputStream.java   | 8 ++------
 .../commons/compress/compressors/bzip2/Compress686Test.java       | 6 ++----
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8c13f8708..1dea723f8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,6 +45,7 @@ The <action> type attribute can be add,update,fix,remove.
   </properties>
   <body>
     <release version="1.27.1" date="YYYY-MM-DD" description="This is a feature 
and maintenance release. Java 8 or later is required.">
+     <action type="fix" issue="COMPRESS-686" dev="ggregory" due-to="Richard 
Blank, Gary Gregory">Compression into BZip2 format has unexpected end of file 
when using a BufferedOutputStream.</action>
      <!-- UPDATE -->
      <action type="update" dev="ggregory" due-to="Dependabot, Gary 
Gregory">Bump org.apache.commons:commons-lang3 from 3.15.0 to 3.16.0 
#556.</action>
     </release>
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
 
b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
index 059be5786..18e53f8e0 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
@@ -433,9 +433,7 @@ public class BZip2CompressorOutputStream extends 
CompressorOutputStream<OutputSt
         if (blockSize > 9) {
             throw new IllegalArgumentException("blockSize(" + blockSize + ") > 
9");
         }
-
         this.blockSize100k = blockSize;
-
         /* 20 is just a paranoia constant */
         this.allowableBlockSize = this.blockSize100k * BASEBLOCKSIZE - 20;
         init();
@@ -560,7 +558,6 @@ public class BZip2CompressorOutputStream extends 
CompressorOutputStream<OutputSt
                 endBlock();
                 endCompression();
             } finally {
-                this.out = null;
                 this.blockSorter = null;
                 this.data = null;
             }
@@ -569,9 +566,8 @@ public class BZip2CompressorOutputStream extends 
CompressorOutputStream<OutputSt
 
     @Override
     public void flush() throws IOException {
-        final OutputStream outShadow = this.out;
-        if (outShadow != null) {
-            outShadow.flush();
+        if (out != null) {
+            super.flush();
         }
     }
 
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
index fcf50c4c6..fe2d893c3 100644
--- 
a/src/test/java/org/apache/commons/compress/compressors/bzip2/Compress686Test.java
+++ 
b/src/test/java/org/apache/commons/compress/compressors/bzip2/Compress686Test.java
@@ -67,12 +67,10 @@ public class Compress686Test {
     }
 
     @ParameterizedTest
-    // TODO
-    // @ValueSource(booleans = { true, false })
-    @ValueSource(booleans = { false })
+    @ValueSource(booleans = { true, false })
     public void testRoundtrip(final boolean bufferCompressOutput) throws 
Exception {
         final Path file = tempDir.resolve("test.txt");
-        final String contents = "random contents";
+        final String contents = "a";
         try (Writer w = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) 
{
             IOUtils.write(contents, w);
         }

Reply via email to