1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-23 01:48:27 +00:00

Read expected buffer size (#17409) (#17430)

Backport of #17409

* Read expected buffer size.

* Changed name.
This commit is contained in:
KN4CK3R
2021-10-25 18:46:56 +02:00
committed by GitHub
parent 06da10b9a1
commit 5159055278
11 changed files with 51 additions and 29 deletions

View File

@@ -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]