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

Using ZipEntry's InputStream to read more than 8K bytes will return error.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 1.2.0, 1.3.0
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
      jar
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.6

      Description

      JDK: 1.2beta4-K
      Locale: all
      OS: solaris2.6

      When using ZipEntry's InputStream to read more than 8K bytes will return error
      bytes. Following is a test program to reproduce it. Please copy rt.jar file to
      your runtime directory.

      ==========================TestZipInputStream.java========================
      import java.io.*;
      import java.util.zip.*;

      public class TestZipInputStream {
          public static void main(String args[]) {
      getClassFromJar("java/awt/Component.class", "rt.jar");
          }
          
          public static void readRemainder(InputStream in, byte[] bytes) throws Exception {
      int len = in.available();
      if (len > bytes.length) len = bytes.length;
      for (int i = 0; i < len; i++) {
      bytes[i] = (byte)in.read();
      }
          }
          public static void getClassFromJar(String className, String jarName) {
      ZipFile zf;
      byte[] bytes1 = null;
      byte[] bytes2 = null;
      try{
      zf = new ZipFile(jarName);
      ZipEntry ze;
      ze = zf.getEntry(className);
      if (ze == null) return;
      InputStream istream = zf.getInputStream(ze);
      bytes1 = new byte[istream.available()];
      bytes2 = new byte[istream.available()];
      istream.read(bytes1);
      istream.close();

      istream = zf.getInputStream(ze);
      readRemainder(istream, bytes2);
      istream.close();
      zf.close();
                 
      int count = 0;
      for (int i = 0; i < bytes1.length; i ++) {
      String tmp1 = "00"+Integer.toHexString(bytes1[i]);
      String tmp2 = "00"+Integer.toHexString(bytes2[i]);
      if (!tmp1.equals(tmp2)) {
      System.out.println("Found a mismatch error: ");
      System.out.println(" Position: " + i);
      System.out.println(" In bytes1 is " + tmp1);
      System.out.println(" In bytes2 is " + tmp2);
      count ++;
      if (count >= 40) {
      break;
      }
      }
      }
      } catch(Exception e){}
          }

      }
      ===========================================================================
      save this file, also copy rt.jar file to your current dir.
      javac TestZipInputStream.java
      java TestZipInputStream
      see the print out message.


      jim.hu@prc 1998-07-14

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              zlisunw Zhenghua Li (Inactive)
              Reporter:
              jhusunw Jim Hu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: