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

Limit bytes passed to http.DetectContentType #10348

Merged
merged 1 commit into from
Apr 9, 2021

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Apr 9, 2021

When detecting the content type for a file, Nomad uses the http.DetectContentType function, which follows the MIME Sniffing spec. This spec defines a set of steps to be applied to the first 512 bytes of the file.

Step 9 is for binary file detection. It looks for a set of predefined byte patterns, one of which is 0x00.

Without limiting the amount of bytes passed to http.DetectContentType, a file smaller than 512 bytes would cause fileBytes to end with several 0x00 bytes, and so the content-type would be set application/octet-stream, preventing the UI from properly displaying the file.

Before:
Screen Shot 2021-04-09 at 1 32 45 PM

After:
Screen Shot 2021-04-09 at 1 32 13 PM

@lgfa29 lgfa29 requested a review from notnoop April 9, 2021 17:24
@lgfa29 lgfa29 merged commit 6af44f8 into main Apr 9, 2021
@lgfa29 lgfa29 deleted the fix-set-proper-content-type branch April 9, 2021 18:37
lgfa29 added a commit that referenced this pull request Apr 9, 2021
lgfa29 added a commit that referenced this pull request Apr 23, 2021
lgfa29 added a commit that referenced this pull request Apr 23, 2021
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2022
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.

2 participants