Skip to content

8278794: Infinite loop in DeflaterOutputStream.finish() #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion jdk/src/share/classes/java/util/zip/Deflater.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -559,6 +559,16 @@ private void ensureOpen() {
throw new NullPointerException("Deflater has been closed");
}

/**
* Returns the value of 'finish' flag.
* 'finish' will be set to true if def.finish() method is called.
*/
boolean shouldFinish() {
synchronized (zsRef) {
return finish;
}
}

private static native void initIDs();
private native static long init(int level, int strategy, boolean nowrap);
private native static void setDictionary(long addr, byte[] b, int off, int len);
Expand Down
14 changes: 10 additions & 4 deletions jdk/src/share/classes/java/util/zip/DeflaterOutputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -221,9 +221,15 @@ public void write(byte[] b, int off, int len) throws IOException {
*/
public void finish() throws IOException {
if (!def.finished()) {
def.finish();
while (!def.finished()) {
deflate();
try{
def.finish();
while (!def.finished()) {
deflate();
}
} catch(IOException e) {
if (usesDefaultDeflater)
def.end();
throw e;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions jdk/src/share/classes/java/util/zip/ZipOutputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -304,7 +304,7 @@ public void closeEntry() throws IOException {
crc.reset();
current = null;
} catch (IOException e) {
if (usesDefaultDeflater && !(e instanceof ZipException))
if (def.shouldFinish() && usesDefaultDeflater && !(e instanceof ZipException))
def.end();
throw e;
}
Expand Down
147 changes: 0 additions & 147 deletions jdk/test/java/util/zip/CloseDeflaterTest.java

This file was deleted.

Loading