Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4532049
Votes 24
Synopsis IllegalArgumentException in ZipInputStream while reading unicode file
Category java:classes_util_jarzip
Reported Against merlin-beta3
Release Fixed 7(b57)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 4244499
Submit Date 28-NOV-2001
Description


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) 
======================================================================
Posted Date : 2006-04-11 19:52:31.0
Work Around
N/A
Evaluation
First four character's-Ansi-numbers from one of the file in readme.zip are
184, 180, 188 and 254. When getUTF8String function from ZipInputStream.java
is invoked during execution, these characters fall under default case (for
above characters case:11 and case:15) in the switch block. The default case is:
default:
                // 10xxxxxx, 1111xxxx
                throw new IllegalArgumentException();
Hence, message 'Exception in thread "main" java.lang.IllegalArgumentException'
gets generated.
So, the question remains is: Do we need to remove case:11 and case:15 from the
default case ?
I removed the case:11 and case:15 from default case and put them in the first 
case in switch statement as: case:0 case:1 case:2 case:3 case:4 case:5 case:6
case:7 case:11 case:15.
The testcase runs fine without any errors/exceptions and unzips the readme.zip
 to generate two files.
  xxxxx@xxxxx   2002-07-09


The above evaluation is incorrect. The real issue is that non-jar zip files usually use encodings other than UTF-8 to encode file names within zip files. This bug is really a duplicate of 4244499.
  xxxxx@xxxxx   2005-1-29 00:22:42 GMT
To use the newly added constructor with a charset 
        ZipInputStream in = new ZipInputStream(new FileInputStream(filename), Charset.forName("ibm437"));
Posted Date : 2009-04-16 22:16:11.0
Comments
  
  Include a link with my name & email   

Submitted On 02-MAR-2003
larryfkm
Fix it as soon as possible please!


Submitted On 05-MAR-2003
javiertb
fix it, please!!


Submitted On 06-MAR-2003
ReynirH
FIX THIS !!!! It's something we need!


Submitted On 08-MAR-2003
durene
Fix it!!
This is very important!!

Kim


Submitted On 11-MAR-2003
liu_wayne10
please fix it.


Submitted On 07-MAY-2003
onlymails
Please fix it soon!


Submitted On 25-MAY-2003
mldav
More than a year to fix a bug. This is unacceptable. It 
reminds me of Microsoft's way of handling software bugs.


Submitted On 04-AUG-2003
javaforidea
fix it please~


Submitted On 02-SEP-2003
lolo3d
FIX THIS !!!! It's something we need!


Submitted On 02-SEP-2003
strimacs
we need this to carry on using java !!


Submitted On 14-SEP-2003
pai911
fix this problem asap...thank you guys


Submitted On 19-NOV-2003
Ikhare
fix it plz.. i'm very suprise that you does'nt support this 
thing!!! 


Submitted On 21-DEC-2003
msg2jiang
fix it please !!


Submitted On 01-MAR-2004
Peter_Schaefer
please fix it !!

it breaks most ZIP files with unicode file names !!!


Submitted On 23-MAR-2005
l9039782
please fix it!!


Submitted On 10-APR-2006
hmm
We need this man. 


Submitted On 10-APR-2006
hmm
We need this man, please fix it.


Submitted On 13-MAR-2007
aaronm32
we need to rewrite our entire product to use a third party zip class because of this problem ... please fix this.


Submitted On 03-DEC-2007
manish_ps
Is this bug expected to be fixed in near future? If so, when, and in which JDK release?



PLEASE NOTE: JDK6 is formerly known as Project Mustang