Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File header and local file header mismatch with unzipWithPassword #238

Closed
nicdex opened this issue Mar 17, 2021 · 8 comments
Closed

File header and local file header mismatch with unzipWithPassword #238

nicdex opened this issue Mar 17, 2021 · 8 comments
Assignees

Comments

@nicdex
Copy link

nicdex commented Mar 17, 2021

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)

@Eliajn
Copy link

Eliajn commented Mar 20, 2021

I am having the same issue, any fix ?

@nicdex
Copy link
Author

nicdex commented Mar 23, 2021

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.

@plrthink
Copy link
Collaborator

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?

@plrthink plrthink self-assigned this Apr 12, 2021
@qiyanlong
Copy link
Contributor

in RNZipArchiveModule.java line 98

@qiyanlong
Copy link
Contributor

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

@qiyanlong
Copy link
Contributor

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

@plrthink
Copy link
Collaborator

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

@plrthink
Copy link
Collaborator

#239

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants