JDK-8278794 : Infinite loop in DeflaterOutputStream.finish()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 7,8,9,10,11,17,18
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2021-12-14
  • Updated: 2025-06-27
  • Resolved: 2022-03-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13 JDK 15 JDK 17 JDK 18 JDK 19 JDK 7 JDK 8 Other
11.0.16-oracleFixed 13.0.12Fixed 15.0.8Fixed 17.0.4-oracleFixed 18.0.2Fixed 19 b15Fixed 7u351Fixed 8u341Fixed openjdk8u432,shenandoah8u432Fixed
Related Reports
Relates :  
Description
Fix for https://bugs.openjdk.java.net/browse/JDK-8193682 has not handled infinite loop issue in DeflaterOutputStream.finish().

Test case :

import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.DeflaterOutputStream;

public class GZipLoopTest {
private static final int FINISH_NUM = 512;

public static void main(String[] args) {
test();
}

private static void test() {

byte[] b = new byte[FINISH_NUM];
Random rand = new Random();
rand.nextBytes(b);
DeflaterOutputStream zip = new DeflaterOutputStream(new OutputStream() {
@Override
public void write(byte[] b, int off, int len) throws IOException{
throw new IOException();
}
@Override
public void write(byte b[]) throws IOException {}
@Override
public void write(int b) throws IOException {}
});
try {
zip.write(b , 0, 512);
} catch (IOException ex) {
ex.printStackTrace();
}
try {
zip.finish();
} catch (IOException ex) {
ex.printStackTrace();
}

for(int i=0;i<3;i++) {
try {
zip.write(b , 0, 512);
} catch (IOException ex) {
ex.printStackTrace();
}
}

}

}





Comments
[jdk8u-fix-request] Approval Request from yan-too I'm backporting this as a follow-up to 8193682. The backport was already done in Oracle jdk8 and all update releases before jdk18. Risk seems low. The fix to 8278794 substituted a new regtest which itself had to be fixed soon after in 8284771. The test is included in this updated form and 8284771 is added as a second issue to this commit.
26-08-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk8u-dev/pull/565 Date: 2024-08-21 11:51:03 +0000
21-08-2024

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk13u-dev/pull/341 Date: 2022-04-14 13:41:15 +0000
14-04-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk15u-dev/pull/196 Date: 2022-04-14 13:18:53 +0000
14-04-2022

Fix request [15u, 13u] This is a necessary continuation to already backported JDK-8193682. Applies with only copyright differences. All relevant tests on major platforms do pass.
14-04-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk11u-dev/pull/975 Date: 2022-04-01 06:01:45 +0000
01-04-2022

Fix request [11u] I backport this for parity with 11.0.16-oracle. Clean backport. A small change to important code. Benefit of fix bigger than risk. Test passes. SAP nighlty testing passed.
01-04-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk17u-dev/pull/287 Date: 2022-03-28 09:30:04 +0000
28-03-2022

Fix Request (17u): Should get backported for parity with 17.0.4-oracle. Applies cleanly except Copyright year update. Test has passed.
28-03-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk18u/pull/53 Date: 2022-03-25 10:18:46 +0000
25-03-2022

Fix request [18u] I'd like to backport it to JDK18u to fix the infinite loop issue with DeflaterOutputStream.finish(). Backport is clean.
22-03-2022

Changeset: ff0b0927 Author: Ravi Reddy <rreddy@openjdk.org> Committer: Lance Andersen <lancea@openjdk.org> Date: 2022-03-18 15:31:30 +0000 URL: https://git.openjdk.java.net/jdk/commit/ff0b0927a2df8b36f8fd6ed41bd4e20e71a5b653
18-03-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7804 Date: 2022-03-13 14:08:57 +0000
13-03-2022