Skip to content

Commit

Permalink
limit bytes passed to http.DetectContentType (#10348)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Apr 9, 2021
1 parent 47951ae commit 6af44f8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
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"
}

0 comments on commit 6af44f8

Please sign in to comment.