8278794: Infinite loop in DeflaterOutputStream.finish()

Reviewed-by: coffeys, lancea
This commit is contained in:
Ravi Reddy 2022-03-18 15:31:30 +00:00 committed by Lance Andersen
parent b2aa085e67
commit ff0b0927a2
5 changed files with 231 additions and 154 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, 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
@ -220,9 +220,15 @@ public class DeflaterOutputStream extends FilterOutputStream {
*/
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;
}
}
}