Monday, October 02, 2006

Java.Util.Zip bugs

I've spent much of this morning trying to track down what appears to be a bug in Java.Util.Zip.Deflater/Inflater. The repro is relatively easy:

byte[] data = new byte[] {
(byte)0xCF, (byte)0xCF, (byte)0xCF, (byte)0xCF, (byte)0xCF
};
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION, true);
DeflaterOutputStream dos = new DeflaterOutputStream(baos, deflater);
dos.write(data);
dos.close();

ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Inflater inflater = new Inflater(true);
InflaterInputStream iis = new InflaterInputStream(bais, inflater);
int count = 0;
while (iis.read() != -1)
count++;
System.out.println("count: "+count);

The values for the data array are specific. Other values also demonstrate the error, but most values work without issue. You can also fix it by not selecting the 'nowrap' option, but that dramatically increases the output size for small inputs.

I'm not sure how to report the issue to Sun, so I'm blogging it here.

1 Comments:

Blogger Tim said...

Weird that your getting that error with the Deflater/Inflater classes. I have yet to have problems and use the classes to compress all binary data that I store for with my applications (such as images, PDFs, etc that are associated with a record). I did a small writeup that has the code for the class I wrote at:
http://timarcher.com/?q=node/35

9:24 PM  

Post a Comment

<< Home