JDK-6916399 : Negative value returned for ZipEntry.getSize(), due to int overflow.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 6u17
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2010-01-13
  • Updated: 2011-02-16
  • Resolved: 2010-05-22
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 5.2.3790]

A DESCRIPTION OF THE PROBLEM :
When I call getSize() on a ZipEntry that has an uncompressed size of 3,827,302,400 bytes, the method returns -467,664,896. This is clearly due to overflow in a 32-bit signed integer. I suspect that the getSize() method must store the value in an int at some point before casting it to a long.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a zip archive containing a file of more than 2^16 bytes. Run
ZipFile zipFile = new ZipFile("file.zip");
ZipEntry entry = zipFile.entries().nextElement();
System.out.println(entry.getSize());

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the program to print the value 3827302400
ACTUAL -
The program prints -467664896

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
See above
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
If the size returned is negative, add it to 0xffffffffl to get the correct value. Of course, this only works if the file size is less than four gigabytes.

long size = entry.getSize();
if (totalBytes < 0) {
    totalBytes = 0xffffffffl + totalBytes;
}

Comments
EVALUATION Dup of #6860950, verified this one is no longer reporducible in 6u18 and JDK7 (reproducible in 6u17).
22-05-2010