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

fix(coderd): correctly handle tar dir entries with missing path separator #12479

Merged
merged 4 commits into from
Mar 11, 2024

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Mar 8, 2024

STACK:
#12477
#12476
#12475
#12479 <-- you are here

I noticed that https://cs.opensource.google/go/go/+/refs/tags/go1.22.1:src/archive/tar/common.go;l=658 has a special case that adds a trailing slash to directory entries.

It turns out that provisionersdk.Tar has been silently stripping these when creating archives for a good while. Some versions of unzip* appear to ignore fileinfo.IsDir() and simply assume that any header without a trailing path separator in the name is a file.

This PR makes the following changes:

  • Adds a unit test to reproduce the behaviour
  • Modifies coderd.CreateZipFromTar to transparently add the trailing path separator
  • Modifies provisionersdk.Tar to add the trailing path separator

* I can reproduce this with UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious how did you notice it? Do you need .zip files specifically or just want to tinker with them?

@johnstcn
Copy link
Member Author

I'm curious how did you notice it? Do you need .zip files specifically or just want to tinker with them?

I was adding the template source into the support bundle for troubleshooting purposes, and noticed that the generated zip file (used zip for consistency cause having a tar in a zip seemed weird) and noticed the issue then when I tested with dev.coder.com.

@johnstcn johnstcn force-pushed the cj/fileszip-directory-member branch from 0e62aab to 9fa67f5 Compare March 11, 2024 13:36
Base automatically changed from cj/files-nil-ptr-deref to main March 11, 2024 14:03
@johnstcn johnstcn merged commit bed61f7 into main Mar 11, 2024
26 checks passed
@johnstcn johnstcn deleted the cj/fileszip-directory-member branch March 11, 2024 14:06
@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants