Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Validate a tar upload instead of storing it unread - #28947

Open
arpitjain099 wants to merge 1 commit into
coder:mainfrom
arpitjain099:fix/validate-tar-upload
Open

Validate a tar upload instead of storing it unread#28947
arpitjain099 wants to merge 1 commit into
coder:mainfrom
arpitjain099:fix/validate-tar-upload

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #28913.

postFile checks the Content-Type header and, for zip, validates the archive with zip.NewReader before converting it. A tar is stored unread, so a gzipped tar sent as application/x-tar is accepted, hashed and returned as a valid file id. The failure then surfaces much later in whatever first reads the filesystem back, which in the report is preview, reported as "Unable to parse workspace tags" with a nil dereference underneath. As the reporter says, an empty template panics too, because the template content is never reached.

The upload path now walks the tar headers and rejects an archive it cannot read, so the mistake gets a 400 where it was made. Only headers are walked, so the cost is proportional to the number of entries rather than their contents. A gzip magic check gives that case its own message, since sending tar czf output is the easy way to hit this and the CLI accepts it.

This is the first of the three suggestions in the issue. I did not touch the reader on the preview side, and I did not add gzip support: accepting gzip changes what the endpoint means and is worth deciding separately, though the asymmetry with coder templates push is the part that cost the reporter the most time.

Tests: TestValidateTar covers a real tar, the all-zero block form that current uploads already use, a gzipped tar and non-archive bytes. TestPostFiles gains a GzippedTar case asserting a 400 whose detail mentions gzip, and an UnreadableTar case.

On what I ran: go test ./coderd/ -run TestValidateTar passes. I could not run the TestPostFiles cases locally, coderdtest.New does not come up in my sandbox and the run sat at files_test.go:46 until the timeout, so those two are unverified by me and rely on CI.

@github-actions github-actions Bot added the community Pull Requests and issues created by the community. label Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Pull Requests and issues created by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gzipped tar upload to /api/v2/files causes nil pointer panic in preview, reported as "Unable to parse workspace tags"

1 participant