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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/allocdir/alloc_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ func detectContentType(fileInfo os.FileInfo, path string) string {
// We ignore errors because this is optional information
if err == nil {
fileBytes := make([]byte, 512)
_, err := f.Read(fileBytes)
n, err := f.Read(fileBytes)
if err == nil {
contentType = http.DetectContentType(fileBytes)
contentType = http.DetectContentType(fileBytes[:n])
}
f.Close()
}
Expand Down
1 change: 1 addition & 0 deletions client/allocdir/alloc_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ func TestAllocDir_DetectContentType(t *testing.T) {
"input/test.json": "application/json",
"input/test.txt": "text/plain; charset=utf-8",
"input/test.go": "text/plain; charset=utf-8",
"input/test.hcl": "text/plain; charset=utf-8",
}
for _, file := range testFiles {
fileInfo, err := os.Stat(file)
Expand Down
3 changes: 3 additions & 0 deletions client/allocdir/input/test.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test "test" {
test = "test"
}