Fix 'ZipException: invalid entry compressed size' mapping non-ASCII text files

When remapping Minecraft + Forge, was failing with:

Exception in thread "main" java.util.zip.ZipException: invalid entry compressed size (expected 13048 but got 13084 bytes)
  at java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:248)
    at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:343)
    at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:238)
    at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:360)
    at net.md_5.specialsource.JarRemapper.remapJar(JarRemapper.java:141)
    at net.md_5.specialsource.SpecialSource.main(SpecialSource.java:220)

Full details: https://gist.github.com/agaricusb/5036166

To fix this, we always create a JarEntry. Explanation from:
http://javahowto.blogspot.com/2011/07/how-to-programmatically-copy-jar-files.html

It usually occurs when text file entries in the source jar file contain some non-ASCII characters such as ^I ^Z ^D ^C. Some common files are META-INF/COPYRIGHT.html, META-INF/LICENSE.txt, etc, probably because these files were created in a non-ASCII editor but saved as text files. Open them in vi or vim to see these offending characters. To avoid this type of ZipException, always create a new JarEntry with the same name, and pass it to putNextEntry() method. Do not pass the existing jar entry from the source jar file to putNextEntry() method.
This commit is contained in:
Agaricus 2013-02-25 21:42:44 -08:00
parent cadc0ef588
commit ea80a4eb91

View File

@ -121,6 +121,8 @@ public class JarRemapper extends Remapper {
entry = new JarEntry(newName == null ? name : newName + ".class");
} else {
entry = new JarEntry(name);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int n;
byte[] b = new byte[1 << 15]; // Max class file size