Skip to content

Commit

Permalink
[COMPRESS-686] Compression into BZip2 format has unexpected end of file
Browse files Browse the repository at this point in the history
when using a BufferedOutputStream
  • Loading branch information
garydgregory committed Aug 15, 2024
1 parent 0a2d564 commit 29c2703
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,7 @@ public BZip2CompressorOutputStream(final OutputStream out, final int blockSize)
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();
Expand Down Expand Up @@ -560,7 +558,6 @@ public void finish() throws IOException {
endBlock();
endCompression();
} finally {
this.out = null;
this.blockSorter = null;
this.data = null;
}
Expand All @@ -569,9 +566,8 @@ public void finish() throws IOException {

@Override
public void flush() throws IOException {
final OutputStream outShadow = this.out;
if (outShadow != null) {
outShadow.flush();
if (out != null) {
super.flush();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ private OutputStream newOutputStream(final Path newFile, final boolean bufferOut
}

@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);
}
Expand Down

0 comments on commit 29c2703

Please sign in to comment.