JDK-8057018 : ZipEntry.setSize() does nothing: re-reading gives -1
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 7u67
  • Priority: P4
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-09-01
  • Updated: 2015-01-22
  • Resolved: 2015-01-22
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
OSX Mavericks 10.9.4

EXTRA RELEVANT SYSTEM CONFIGURATION :
not applicable

A DESCRIPTION OF THE PROBLEM :
producing a zipped file from several files and directories works OK,
however, the call ZipEntry.setSize(long) is ignored for any value of size
(values strictly < 10 000 000)
unzipping or listing the zip file shows that all file sizes are -1.
Unzipping works OK, but any software that predicts the unzipped size fails.

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      ZipEntry entry;
      ZipOutputStream zipOutput;
...........
         zipOutput = new ZipOutputStream(new FileOutputStream(temporaryFile));

               entry = new ZipEntry(s);  // Zip name of the file
               entry.setSize(length);      // from File.length()
               entry.setTime(f.lastModified());

               operation = "WRITING ZIP-ENTRY"; // To identify at IOException catch.
               zipOutput.putNextEntry(entry);


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
We expect 'length' to appear in a listing or zip-info of the zip-file.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
as above
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
"Drop all software that checks the uncompressed total size of the zipped files.

B.t.w.: on the internet I found that this bug was already there in JAVA 2.1 !!!


Comments
In "compressed" mode (default for the ZipOutputStream), the uncompressed size, the compressed size, and the crc-32 values are stored in the data descriptor recorder immediately following the compressed entry data. The ZIP spec requires the bit 3 of the loc flag field should be marked and the size/csize/crc32 in the loc header should be set to zero.
22-01-2015