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

method java.util.zip.GZIPInputStream.read permits reading if closed.

    Details

    • Subcomponent:
      jar
    • Resolved In Build:
      1.2fcs
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: sdC67446 Date: 02/09/98


      method java.util.zip.GZIPInputStream.read allows reading after calling method close().

      Here is the JLS quote:
      --------------------------------------------------
      22.3.1 public abstract int read() throws IOException

      The general contract of read is that it reads one byte from the input stream.
      The byte is returned as an integer in the range 0 to 255 (0x00-0xff).
      If no byte is available because the stream is at end of file,
      the value -1 is returned.

      This method blocks until input data is available,
      end of file is detected, or an exception is thrown.

      If the byte cannot be read for any reason other than end of file,
      an IOException is thrown. In particular, an IOException is
      thrown if the input stream has been closed (§22.3.6).

      Here is the test demonstrating the bug:
      -----------------Test.java------------------------
      import java.util.zip.*;
      import java.io.*;

      public class Test {
        
        public static void main(String[] args) {
          
          try {
            InputStream bis = new ByteArrayInputStream(compressed);
            GZIPInputStream gis = new GZIPInputStream(bis);
            gis.close();
            int a = gis.read();
            System.out.println("Can read after close().");
          } catch ( IOException e ) {
            System.out.println("It's ok.");
          }
        }
        // compressed stub data
        static byte[] compressed = {
          31,-117,8,0,0,0,0,0,0,0,-85,-107,-79,74,85,97,117,48,
          -9,117,-47,114,15,-87,-27,-9,-54,-48,49,-108,17,19,20,
          118,-87,-84,78,-15,-10,-87,-112,51,115,16,85,81,54,11,
          114,44,11,98,116,17,102,-10,72,-10,80,-79,101,14,47,-50,
          16,117,-9,-83,16,13,-55,83,83,103,-30,-117,-42,-82,-105,
          -119,46,-16,20,-111,-85,-16,-48,54,79,-53,-76,116,
          -80,-78,77,-88,-85,50,113,-54,15,-74,-28,-44,101,-43,47,
          85,54,-74,1,0,85,69,28,117,100,0,0,0
        };
      }
      ---------Output from the test---------------------
      Can read after close().
      --------------------------------------------------

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                zlisunw Zhenghua Li (Inactive)
                Reporter:
                sdmitriesunw Sergei Dmitriev (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: