Make sure Upload-Offset in PATCH request is greater than 0

This commit is contained in:
Naren Venkataraman 2015-11-04 04:33:32 -05:00
parent 1f6aac2a49
commit e451dc5f65
1 changed files with 7 additions and 7 deletions

View File

@ -284,6 +284,13 @@ func (handler *Handler) patchFile(w http.ResponseWriter, r *http.Request) {
return
}
//Check for presence of a valid Upload-Offset Header
offset, err := strconv.ParseInt(r.Header.Get("Upload-Offset"), 10, 64)
if err != nil || offset < 0 {
handler.sendError(w, r, ErrInvalidOffset)
return
}
id := r.URL.Query().Get(":id")
// Ensure file is not locked
@ -312,13 +319,6 @@ func (handler *Handler) patchFile(w http.ResponseWriter, r *http.Request) {
return
}
// Ensure the offsets match
offset, err := strconv.ParseInt(r.Header.Get("Upload-Offset"), 10, 64)
if err != nil {
handler.sendError(w, r, ErrInvalidOffset)
return
}
if offset != info.Offset {
handler.sendError(w, r, ErrIllegalOffset)
return