Return appropriate errors if upload-length is misused in PATCH requests

This commit is contained in:
Adam Jensen 2018-06-03 12:24:51 -04:00
parent 22fdd3935b
commit a366b00e3e
1 changed files with 19 additions and 11 deletions

View File

@ -459,7 +459,9 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
return return
} }
if handler.composer.UsesLengthDeferrer && info.SizeIsDeferred && r.Header.Get("Upload-Length") != "" { if r.Header.Get("Upload-Length") != "" {
if handler.composer.UsesLengthDeferrer {
if info.SizeIsDeferred {
uploadLength, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64) uploadLength, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
if err != nil || uploadLength < 0 || uploadLength < info.Offset || uploadLength > handler.config.MaxSize { if err != nil || uploadLength < 0 || uploadLength < info.Offset || uploadLength > handler.config.MaxSize {
handler.sendError(w, r, ErrInvalidUploadLength) handler.sendError(w, r, ErrInvalidUploadLength)
@ -472,6 +474,12 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
handler.sendError(w, r, err) handler.sendError(w, r, err)
return return
} }
} else {
handler.sendError(w, r, ErrInvalidUploadLength)
}
} else {
handler.sendError(w, r, ErrNotImplemented)
}
} }
if err := handler.writeChunk(id, info, w, r); err != nil { if err := handler.writeChunk(id, info, w, r); err != nil {