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

FileManager.unzipItem doesn't work with some URLs created from relative paths #217

Open
Aquilosion opened this issue Mar 16, 2021 · 3 comments

Comments

@Aquilosion
Copy link

Summary

If I try to unzip a file (using the FileManager extension) to a URL which was created with a relative path, the extraction fails with an error. Using the relative URL's absoluteURL does work.

Steps to Reproduce

  1. Create a "relative" URL, such as: URL(fileURLWithPath: "../../Resources", isDirectory: true).
  2. Pass that URL as the to parameter of FileManager.unzipItem (along with a URL to a valid zip file).

Expected Results

The contents of the zip file is successfully extracted to the target location.

Actual Results

An error is thrown. For example, if the zip file contains a compressed directory called "media", the error is:

The item couldn’t be opened because the file name “media” is invalid.

If I get the absoluteURL of the target URL first, it does work.

Regression & Version

Tested with 0.9.12.

Findings

I think this is caused because the implementation of URL.isContained(in:) (defined in FileManager+ZIP.swift) calls standardized on the URLs first, which outputs the wrong URL when it is created with a relative path. For example:

fileManager.changeCurrentDirectoryPath("/Users/Robert/Documents")

let relativePath = "../../David/Documents"
let relativeURL = URL(fileURLWithPath: relativePath)

relativeURL.absoluteString
// file:///Users/David/Documents

relativeURL.standardized.absoluteString
// file:///Users/Robert/Documents/David/Documents
@ckp-aayushi
Copy link

ckp-aayushi commented Feb 9, 2024

Summary
Extracting zip file is failing intermittently on latest release i.e 0.9.18. I was able to unzip with previous releases.

Steps To Reproduce:
There are no consistent steps. It will fail intermittently.

Actual Result:
On debugging, unzip API is throwing following error:

The item couldn’t be opened because the file name “Bundle” is invalid.

Expected:
Should be able to unzip always.

Version:
0.9.18

@weichsel
Copy link
Owner

weichsel commented Feb 9, 2024

Extracting zip file is failing intermittently on latest release i.e 0.9.18. I was able to unzip with previous releases.

Do the archives you are trying to unzip contain symlinks that point outside of the destination directory? If so, you now have to opt-into pre-0.9.18 behavior by passing allowUncontainedSymlinks: true to unzipItem.

@ckp-aayushi
Copy link

Do the archives you are trying to unzip contain symlinks that point outside of the destination directory? If so, you now have to opt-into pre-0.9.18 behavior by passing allowUncontainedSymlinks: true to unzipItem.

No, zip file does not contain symlinks. This is working fine with 0.9.17 and is seen on 0.9.18 and 0.9.19 versions.
We need to use 0.9.19 for Privacy manifest changes. Pls suggest how to resolve this issue.

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

3 participants