limit bytes passed to http.DetectContentType (#10348)
This commit is contained in:
parent
3113cced7b
commit
37f1c37fab
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
test "test" {
|
||||
test = "test"
|
||||
}
|
Loading…
Reference in New Issue