diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-10-24 23:12:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-24 22:12:43 +0100 |
commit | f99d50fc9f8baf406f32a491b214f8a13617d086 (patch) | |
tree | b3cd8a1304e522f111690e9f68130e663012bb16 /modules/typesniffer | |
parent | 932780c2bbae09f052e2fcd1a0701966483496e8 (diff) | |
download | gitea-f99d50fc9f8baf406f32a491b214f8a13617d086.tar.gz gitea-f99d50fc9f8baf406f32a491b214f8a13617d086.zip |
Read expected buffer size (#17409)
* Read expected buffer size.
* Changed name.
Diffstat (limited to 'modules/typesniffer')
-rw-r--r-- | modules/typesniffer/typesniffer.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/typesniffer/typesniffer.go b/modules/typesniffer/typesniffer.go index d257b8179b..9e29b3557c 100644 --- a/modules/typesniffer/typesniffer.go +++ b/modules/typesniffer/typesniffer.go @@ -10,6 +10,8 @@ import ( "net/http" "regexp" "strings" + + "code.gitea.io/gitea/modules/util" ) // Use at most this many bytes to determine Content Type. @@ -86,8 +88,8 @@ func DetectContentType(data []byte) SniffedType { // DetectContentTypeFromReader guesses the content type contained in the reader. func DetectContentTypeFromReader(r io.Reader) (SniffedType, error) { buf := make([]byte, sniffLen) - n, err := r.Read(buf) - if err != nil && err != io.EOF { + n, err := util.ReadAtMost(r, buf) + if err != nil { return SniffedType{}, fmt.Errorf("DetectContentTypeFromReader io error: %w", err) } buf = buf[:n] |