robovm icon indicating copy to clipboard operation
robovm copied to clipboard

Unexpected end of ZLIB input stream only on iOS

Open Shanezor12 opened this issue 3 years ago • 2 comments

Issue details

When unzipping a particular zip file, I would consistently receive an Error/Unexpected End of File Exception. This only happened for this particular zip and only on iOS. We've used this system across multiple projects and many zip files and have never ran into this type of issue before.

Reproduction steps/code

Use zip4j to decompress the bad.zip file on iOS

Configuration

This only could be reproduced on iOS devices. Android and Windows based systems all had no problem with the zip file

Build Tools:

  • [ ] IDEA plugin
  • [ ] Eclipse plugin
  • [x ] Gradle plugin

Versions:

  • Robovm: 2.3.13
  • XCode: 13
  • JDK: 8

Build Targets: iPhone SE (14.5.1)

Stacktrace

java.io.EOFException: Unexpected end of ZLIB input stream
	at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:171)
	at net.lingala.zip4j.unzip.Unzip.initExtractAll(Unzip.java:83)
	at net.lingala.zip4j.unzip.Unzip.extractAll(Unzip.java:73)
	at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:488)
	at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:451)
Caused by: net.lingala.zip4j.exception.ZipException: java.io.EOFException: Unexpected end of ZLIB input stream
	at net.lingala.zip4j.unzip.UnzipEngine.unzipFile(UnzipEngine.java:98)
	at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:160)
	... 8 more
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
	at net.lingala.zip4j.io.InflaterInputStream.fill(InflaterInputStream.java:114)
	at net.lingala.zip4j.io.InflaterInputStream.read(InflaterInputStream.java:81)
	at net.lingala.zip4j.io.ZipInputStream.read(ZipInputStream.java:45)
	at net.lingala.zip4j.io.ZipInputStream.read(ZipInputStream.java:41)
	at net.lingala.zip4j.unzip.UnzipEngine.unzipFile(UnzipEngine.java:81)
	... 9 more

bad.zip

Shanezor12 avatar Apr 22 '22 16:04 Shanezor12

hi, already have answered over the gitter and will copy here:

have tested sample you have provided:

        String badZip = NSBundle.getMainBundle().findResourcePath("bad", "zip");
        ZipFile zf = new ZipFile(new File(badZip));
        try {
            zf.extractAll(NSPathUtilities.getTemporaryDirectory());
        } catch (ZipException e) {
            e.printStackTrace();
        }

and it fails as you have described (used net.lingala.zip4j:zip4j:2.10.0) while java.util.zip.ZipFile can handle this file without issue:

        String badZip = NSBundle.getMainBundle().findResourcePath("bad", "zip");
        try {
            ZipFile zf = new ZipFile(new File(badZip));
            Enumeration<? extends ZipEntry> entries = zf.entries();
            while (entries.hasMoreElements()) {
                ZipEntry ze = entries.nextElement();
                System.out.println(ze.getName());
                try (InputStream is = zf.getInputStream(ze)) {
                    while (is.available() != 0)
                        is.read();
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

I suppose there is an issue with zip4j itself

dkimitsa avatar Apr 22 '22 16:04 dkimitsa

private void testZip () throws FileNotFoundException {
        FileInputStream fis = new FileInputStream(NSBundle.getMainBundle().findResourcePath("bad", "zip"));
        ZipInputStream zis = null;

        byte[] buffer = new byte[1];
        try {
            zis = new ZipInputStream(fis);
            ZipEntry ze = zis.getNextEntry();
            while (ze != null){

                if(ze.isDirectory()) {
                    System.out.println("Found dir " + ze.getName());
                } else {
                    System.out.println("Found file " + ze.getName());
                    int len;
                    int total = 0;
                    while ((len = zis.read(buffer)) > 0) {
                        total += len;
                    }
                    System.out.println("total read " + total);
                }

                zis.closeEntry();
                ze = zis.getNextEntry();
            }
            zis.closeEntry();

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(zis != null) {
                    zis.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
Found dir ETC2/
Found dir ETC2/world/
Found dir ETC2/world/units/
Found dir ETC2/world/units/pacha/
Found dir ETC2/world/units/pacha/vfx/
Found file ETC2/world/units/pacha/vfx/pacha_skill1_smoke.np
total read 4102

Tom-Ski avatar Apr 22 '22 17:04 Tom-Ski