From 7b2523aa9c5d31c54b3963e4d3a341434981a0a2 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Wed, 12 Feb 2025 17:01:11 +0530 Subject: [PATCH] 8349909: jdk.internal.jimage.decompressor.ZipDecompressor does not close the Inflater in exceptional cases --- .../jimage/decompressor/ZipDecompressor.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java b/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java index f8e9d46a77725..b5cba5a17dc60 100644 --- a/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java +++ b/src/java.base/share/classes/jdk/internal/jimage/decompressor/ZipDecompressor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -50,16 +50,18 @@ static byte[] decompress(byte[] bytesIn, int offset, long originalSize) throws E } byte[] bytesOut = new byte[(int) originalSize]; + int count = 0; Inflater inflater = new Inflater(); - inflater.setInput(bytesIn, offset, bytesIn.length - offset); + try { + inflater.setInput(bytesIn, offset, bytesIn.length - offset); - int count = 0; - while (!inflater.finished() && count < originalSize) { - count += inflater.inflate(bytesOut, count, bytesOut.length - count); + while (!inflater.finished() && count < originalSize) { + count += inflater.inflate(bytesOut, count, bytesOut.length - count); + } + } finally { + inflater.end(); } - inflater.end(); - if (count != originalSize) { throw new IOException("Resource content size mismatch"); }