Reset compressed size when combining JAR/ZIP archives.
Summary:
From https://github.com/facebook/buck/pull/16.
zlib does not always deflate a resource to the same compressed size as
the original input. The input resource may have been compressed using
a different version of libz, or different compression settings.
Before adding each entry to the ZIP, clone the entry and reinitialize
the compressed field to -1 as is done by the more commonly used
`ZipEntry(String)` constructor.
This fixes a rare case where including a JAR in a `java_binary()` may
throw an error such as:
invalid entry compressed size (expected 4271 but got 4275 bytes)
Test Plan: Sandcastle builds.
diff --git a/src/com/facebook/buck/java/JarDirectoryStep.java b/src/com/facebook/buck/java/JarDirectoryStep.java
index 28e09c2..34dfb58 100644
--- a/src/com/facebook/buck/java/JarDirectoryStep.java
+++ b/src/com/facebook/buck/java/JarDirectoryStep.java
@@ -215,7 +215,12 @@
continue;
}
- jar.putNextEntry(entry);
+ // Reinitialize the compressed field to -1 as the ZipEntry(String) constructor would.
+ // See https://github.com/spearce/buck/commit/8338c1c3d4a546f577eed0c9941d9f1c2ba0a1b7.
+ ZipEntry newEntry = new ZipEntry(entry);
+ newEntry.setCompressedSize(-1);
+
+ jar.putNextEntry(newEntry);
InputStream inputStream = zip.getInputStream(entry);
ByteStreams.copy(inputStream, jar);
jar.closeEntry();