Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8210471

GZIPInputStream constructor could leak an un-end()ed Inflater

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • None
    • core-libs
    • None

      Colleague Tobias Thierer writes:

      =====

      When the constructor GZIPInputStream(InputStream,int) throws an exception (eg. when encountering invalid data), the Inflater constructed earlier is not end()ed before it becomes eligible for garbage collection. This means that the Inflater's zsref is not reliably cleared (relies on finalization alone).

      The patch below fixes this problem in the case of Exception; in the case of Error, it still leaves the Inflater in un-end()ed state.

      --- a/src/java.base/share/classes/java/util/zip/GZIPInputStream.java Thu Jun 21 08:58:59 2018 -0300
      +++ b/src/java.base/share/classes/java/util/zip/GZIPInputStream.java Thu Sep 06 14:15:23 2018 +0100
      @@ -77,7 +77,12 @@
           public GZIPInputStream(InputStream in, int size) throws IOException {
               super(in, new Inflater(true), size);
               usesDefaultInflater = true;
      - readHeader(in);
      + try {
      + readHeader(in);
      + } catch (Exception e) {
      + inf.end();
      + throw e;
      + }
           }
       
           /**

            jpai Jaikiran Pai
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: