From b4e785af8a59affa1c3ae2cc879f750ab9113c15 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Mon, 22 Mar 2021 02:42:34 +0000 Subject: [PATCH] fup: fix minor issue with shorter-than-512 byte file uploads Reader.Read is permitted to return EOF on short reads, which had not been anticipated by this code. There's probably more instances of this lurking... --- web/fup/fuphttp/httpupload.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/fup/fuphttp/httpupload.go b/web/fup/fuphttp/httpupload.go index febdb3ddce..2de4d5a927 100644 --- a/web/fup/fuphttp/httpupload.go +++ b/web/fup/fuphttp/httpupload.go @@ -174,7 +174,7 @@ func (a *Application) upload(rw http.ResponseWriter, r *http.Request) { if mimeType == "" { // We'll need to sniff it... buf := make([]byte, 512) - if _, err := r.Body.Read(buf); err != nil { + if _, err := r.Body.Read(buf); err != nil && !errors.Is(err, io.EOF) { log.Printf("upload: Read for MIME sniffing: %v", err) a.internalError(rw, r) return