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

java.util.zip.ZipInputStream.read permits reading after closeEntry

    Details

    • Subcomponent:
      jar
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: sdC67446 Date: 09/21/98


      method java.util.zip.ZipInputStream.read allows reading
      after calling method closeEntry().

      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(zipped);
            ZipInputStream zis = new ZipInputStream(bis);
            ZipEntry ent = zis.getNextEntry();

            zis.closeEntry();
            int temp = zis.read();
            System.out.println("Can read after closeEntry().");

            zis.close();
          } catch ( IOException e ) {
            System.out.println(e);
          }
        }
        
        static byte[] zipped = {
          80,75,3,4,20,0,8,0,8,0,18,113,40,36,0,0,0,0,0,0,0,0,0,0,0,0,
          1,0,0,0,49,-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,80,75,7,
          8,85,69,28,117,102,0,0,0,100,0,0,0,80,75,1,2,20,0,20,0,8,0,8,0,18,
          113,40,36,85,69,28,117,102,0,0,0,100,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,
          0,0,0,0,0,0,49,80,75,5,6,0,0,0,0,1,0,1,0,47,0,0,0,-107,0,0,0,0,0
        };
      }
      ---------Output from the test---------------------
      Can read after closeEntry().
      --------------------------------------------------

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

        Attachments

          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: