Closed Shanezor12 closed 1 year ago
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
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
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:
Versions:
Build Targets: iPhone SE (14.5.1)
Stacktrace
bad.zip