mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8193682: Infinite loop in ZipOutputStream.close()
Reviewed-by: lancea, coffeys
This commit is contained in:
parent
abaa073bcb
commit
1e9ed54d36
4 changed files with 229 additions and 67 deletions
|
@ -157,24 +157,30 @@ public class GZIPOutputStream extends DeflaterOutputStream {
|
|||
*/
|
||||
public void finish() throws IOException {
|
||||
if (!def.finished()) {
|
||||
def.finish();
|
||||
while (!def.finished()) {
|
||||
int len = def.deflate(buf, 0, buf.length);
|
||||
if (def.finished() && len <= buf.length - TRAILER_SIZE) {
|
||||
// last deflater buffer. Fit trailer at the end
|
||||
writeTrailer(buf, len);
|
||||
len = len + TRAILER_SIZE;
|
||||
out.write(buf, 0, len);
|
||||
return;
|
||||
try {
|
||||
def.finish();
|
||||
while (!def.finished()) {
|
||||
int len = def.deflate(buf, 0, buf.length);
|
||||
if (def.finished() && len <= buf.length - TRAILER_SIZE) {
|
||||
// last deflater buffer. Fit trailer at the end
|
||||
writeTrailer(buf, len);
|
||||
len = len + TRAILER_SIZE;
|
||||
out.write(buf, 0, len);
|
||||
return;
|
||||
}
|
||||
if (len > 0)
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
if (len > 0)
|
||||
out.write(buf, 0, len);
|
||||
// if we can't fit the trailer at the end of the last
|
||||
// deflater buffer, we write it separately
|
||||
byte[] trailer = new byte[TRAILER_SIZE];
|
||||
writeTrailer(trailer, 0);
|
||||
out.write(trailer);
|
||||
} catch (IOException e) {
|
||||
if (usesDefaultDeflater)
|
||||
def.end();
|
||||
throw e;
|
||||
}
|
||||
// if we can't fit the trailer at the end of the last
|
||||
// deflater buffer, we write it separately
|
||||
byte[] trailer = new byte[TRAILER_SIZE];
|
||||
writeTrailer(trailer, 0);
|
||||
out.write(trailer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue