mockingbot / react-native-zip-archive

Zip archive utility for react-native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File header and local file header mismatch with unzipWithPassword

nicdex opened this issue · comments

Describe the bug
I get this call stack when trying to unzip a file with password. I am certain my password is correct. Also the same process works (backup, then restore) if I use zip/unzip (no password).

03-16 16:59:49.238 12922 12957 E ReactNativeJS: RestoreScreen._restoreFromBackup reading file failed: Error: Failed to unzip file, due to: net.lingala.zip4j.exception.ZipException: File header and local file header mismatch
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.tasks.AbstractExtractFileTask.verifyNextEntry(AbstractExtractFileTask.java:151)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.tasks.AbstractExtractFileTask.extractFile(AbstractExtractFileTask.java:59)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.tasks.ExtractFileTask.executeTask(ExtractFileTask.java:43)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.tasks.ExtractFileTask.executeTask(ExtractFileTask.java:22)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.tasks.AsyncZipTask.performTaskWithErrorHandling(AsyncZipTask.java:46)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.tasks.AsyncZipTask.execute(AsyncZipTask.java:40)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.ZipFile.extractFile(ZipFile.java:689)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at net.lingala.zip4j.ZipFile.extractFile(ZipFile.java:489)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at com.rnziparchive.RNZipArchiveModule$1.run(RNZipArchiveModule.java:98)
03-16 16:59:49.238 12922 12957 E ReactNativeJS: at java.lang.Thread.run(Thread.java:761)

To Reproduce

  1. Create a zip file using zipWithPassword using STANDARD encryptionType on Android.
  2. Unzip using unzipWithPassword the file and it throws the above exception.

Expected behavior
I expected to be able to extract my zip file the same way it does without password.

Env (please complete the following information):

  • Device: Android Emulator
  • OS: Android
  • OS Version: 7.1.1
  • Package Version: 6.0.2

Additional context
The resulting encrypted zip file can also be open using Desktop zip program (Ark on kubuntu)

I am having the same issue, any fix ?

I would have give it a try myself but I don't know Java / Android enough.
I ended up encrypting the zip myself by, anyhow it fits better my requirements as a protected zip still shows filename, which can be a security leak in my case.

I found that the error said ‘Error: Failed to unzip file, due to: net.lingala.zip4j.exception.ZipException: File header and local file header mismatch’,this may be related to the file you are unzipping. Could you share a reproducible file to let me dig into?

in RNZipArchiveModule.java line 98

    zipFile.extractFile(fileHeader, destDirectory);
        if (!fileHeader.isDirectory()) {
          extractedFileNames.add(fileHeader.getFileName());
        } 

change to if (!fileHeader.isDirectory()) {
zipFile.extractFile(fileHeader, destDirectory);
extractedFileNames.add(fileHeader.getFileName());
}

Good job @qiyanlong, just released the 6.0.3 which include this fix