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

Negative value returned for ZipEntry.getSize(), due to int overflow.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u17
    • core-libs

      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;
      }

            sherman Xueming Shen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: