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

unzipping a file with with read only permissions on its zipped folders breaks #9332

Closed
trashhalo opened this issue Jan 22, 2025 · 5 comments · Fixed by #9335
Closed

unzipping a file with with read only permissions on its zipped folders breaks #9332

trashhalo opened this issue Jan 22, 2025 · 5 comments · Fixed by #9335
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@trashhalo
Copy link

Describe the bug
When you try to unzip a file that has permissions set to be read only on internal directory structure it will blow up bad match eaccess error because it's trying to create files in the folder that's read only.

To Reproduce

  1. download zip file file_test.zip
  2. mkdir target
  3. :zip.unzip(~c"file_test.zip", cwd: ~c"target") (elixir code)
iex(1)> :zip.unzip(~c"file_test.zip", cwd: ~c"target")
{:error,
 {:EXIT,
  {{:badmatch, {:error, :eacces}},
   [
     {:zip, :file_io, 2, [file: ~c"zip.erl", line: 2757]},
     {:zip, :get_z_file, 11, [file: ~c"zip.erl", line: 2286]},
     {:zip, :get_z_files, 5, [file: ~c"zip.erl", line: 2231]},
     {:zip, :do_unzip, 2, [file: ~c"zip.erl", line: 425]},
     {:zip, :unzip, 2, [file: ~c"zip.erl", line: 410]},
     {:elixir, :eval_external_handler, 3, [file: ~c"src/elixir.erl", line: 386]},
     {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 919]},
     {:elixir, :eval_forms, 4, [file: ~c"src/elixir.erl", line: 364]}
   ]}}}
iex(2)> :zip.unzip(~c"file_test.zip")

Expected behavior
It unzips the files into the folder target.

Affected versions
OTP 27.2, but my guess is it was introduced in 27.1

Additional context
Id also settle for a option to not carry forward permissions from the zip file. Suprisingly it works if you dont pass a cwd. 🤔

@trashhalo trashhalo added the bug Issue is reported as a bug label Jan 22, 2025
@trashhalo
Copy link
Author

@garazdawi I think you may have introduced this issue here. d6c4e1f

@garazdawi
Copy link
Contributor

Thanks for the report. The right thing to do here is probably to set all directory permissions after we have created all files and directories... and there should probably also be an option added to ignore all permissions in the archive.

garazdawi added a commit to garazdawi/otp that referenced this issue Jan 23, 2025
The permissions were set on extrected directories before the files within
were extracted, making it impossible to create the files within. This
commit delays all directory permissions to after all files/directories
have been created so that they can all be set.

Closed erlang#9332
garazdawi added a commit to garazdawi/otp that referenced this issue Jan 23, 2025
The permissions were set on extrected directories before the files within
were extracted, making it impossible to create the files within. This
commit delays all directory permissions to after all files/directories
have been created so that they can all be set.

Closed erlang#9332
@garazdawi garazdawi linked a pull request Jan 23, 2025 that will close this issue
@garazdawi
Copy link
Contributor

Fix available in #9335, please test it with your original problem.

@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Jan 23, 2025
@akoutmos
Copy link

akoutmos commented Jan 31, 2025

Just came across this bug as well and it was a doozy to figure out what was going on lol.

One work around for this while we wait for a new release is to do (in Elixir) :zip.extract(zip_path, [:memory]) and then manually go through the contents of the files and write the files out manually. This way you don't need to worry about the file permissions.

@trashhalo
Copy link
Author

Just came across this bug as well and it was a doozy to figure out what was going on lol.

One work around for this while we wait for a new release is to do (in Elixir) :zip.extract(zip_path, [:memory]) and then manually go through the contents of the files and write the files out manually. This way you don't need to worry about the file permissions.

I'm so glad it wasn't just me that lost a day to try to figure this out. Was one of the harder bugs I've hit to trace. Huge thanks to @garazdawi for quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants