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...
This commit is contained in:
Luke Granger-Brown 2021-03-22 02:42:34 +00:00
parent a9a437cee4
commit b4e785af8a

View file

@ -174,7 +174,7 @@ func (a *Application) upload(rw http.ResponseWriter, r *http.Request) {
if mimeType == "" { if mimeType == "" {
// We'll need to sniff it... // We'll need to sniff it...
buf := make([]byte, 512) 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) log.Printf("upload: Read for MIME sniffing: %v", err)
a.internalError(rw, r) a.internalError(rw, r)
return return