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

IllegalArgumentException in ZipInputStream while reading unicode file

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b57
    • CPU:
      x86
    • OS:
      windows_98

      Description

      Name: nt126004 Date: 11/27/2001


      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

      java.until.zip.ZipFile or ZipInputStream can't unzip file(unicode name) in zip
      by winzip8.0

      source code:
      import java.util.zip.*;
      import java.io.*;
      public class UnzipF {
          
         private String filename;
          
         public UnzipF(String filename){
            this.filename = filename;
         }
          
         public boolean unzip(){
            try {
               String topdir = filename.substring(0,filename.indexOf(".zip"));
               if (!(new java.io.File(topdir)).mkdir()) System.out.println("topdir of
      filename can't created!");
                
               ZipInputStream in = new ZipInputStream(new FileReader(filename));
               //ZipInputStream in = new ZipInputStream(new DataInputStream(new
      java.io.FileInputStream(filename)));
               ZipEntry entry;
               String entryname;
               byte[] buf = new byte[4096];
               int len,length;
               String outFilename;
               OutputStream out;
               String dirname;
               while ((entry = in.getNextEntry()) != null) {
                  entryname = entry.getName();
                  if (!entry.isDirectory()){
                     int index = entryname.lastIndexOf('/');
                     if(index != -1){
                        dirname = entryname.substring(0,index+1);
                        if (!(new java.io.File(topdir+'/'+dirname)).exists()) (new
      java.io.File(topdir+'/'+dirname)).mkdirs() ;
                     }
                     outFilename = topdir + '/' + entryname;
                     out = new java.io.FileOutputStream(outFilename);
                     length = 0 ;
                     while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                        length=length+len;
                     }
                     out.close();
                     System.out.print("outFilename:"+outFilename);
                     System.out.println(" length:"+length);
                     //System.in.read();
                  }
                  else {
                     if (!(new java.io.File(topdir+'/'+entryname)).exists()) (new
      java.io.File(topdir+'/'+entryname)).mkdirs() ;
                     System.out.println("topdir+'/'+entryname:"+topdir+'/'+entryname);
                  }
               }
               in.close();
               return true;
            } catch (IOException e) {
             System.out.println("test");
             System.out.println(e.getMessage());
              return false;
            }
         }
         public static void main(String args[]) {
           UnzipF uf = new UnzipF(args[0]);
           uf.unzip();
         }
      }

      readme.zip's entry(zip by winzip8.0):
      复件 readme.txt
      readme.txt


      commad:java UnzipF readme.zip

      Exception:
      Exception in thread "main" java.lang.IllegalArgumentException
              at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:291)
              at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:230)
              at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:75)
              at UnzipF.unzip(UnzipF.java:24)
              at UnzipF.main(UnzipF.java:58)
      (Review ID: 135772)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                nthompsosunw Nathanael Thompson (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: