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 /services/attachment | |
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 'services/attachment')
-rw-r--r-- | services/attachment/attachment.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/services/attachment/attachment.go b/services/attachment/attachment.go index 7500a8ac3a..f747ccec3e 100644 --- a/services/attachment/attachment.go +++ b/services/attachment/attachment.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/upload" + "code.gitea.io/gitea/modules/util" "github.com/google/uuid" ) @@ -41,10 +42,8 @@ func NewAttachment(attach *models.Attachment, file io.Reader) (*models.Attachmen // UploadAttachment upload new attachment into storage and update database func UploadAttachment(file io.Reader, actorID, repoID, releaseID int64, fileName string, allowedTypes string) (*models.Attachment, error) { buf := make([]byte, 1024) - n, _ := file.Read(buf) - if n > 0 { - buf = buf[:n] - } + n, _ := util.ReadAtMost(file, buf) + buf = buf[:n] if err := upload.Verify(buf, fileName, allowedTypes); err != nil { return nil, err |