From c498fbdf61db80b517e82c1c995fb795d5f52f68 Mon Sep 17 00:00:00 2001 From: chrislu Date: Mon, 17 Nov 2025 16:00:28 -0800 Subject: [PATCH] range on empty object or zero-length --- weed/s3api/s3api_object_handlers.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index f6e686143..ec33edf6c 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -629,6 +629,12 @@ func (s3a *S3ApiServer) streamFromVolumeServers(w http.ResponseWriter, r *http.R if parts[0] == "" && parts[1] != "" { // Suffix range: bytes=-N (last N bytes) if suffixLen, err := strconv.ParseInt(parts[1], 10, 64); err == nil { + // RFC 7233: suffix range on empty object or zero-length suffix is unsatisfiable + if totalSize == 0 || suffixLen <= 0 { + w.Header().Set("Content-Range", fmt.Sprintf("bytes */%d", totalSize)) + w.WriteHeader(http.StatusRequestedRangeNotSatisfiable) + return fmt.Errorf("invalid suffix range for empty object") + } if suffixLen > totalSize { suffixLen = totalSize } @@ -871,6 +877,12 @@ func (s3a *S3ApiServer) streamFromVolumeServersWithSSE(w http.ResponseWriter, r if parts[0] == "" && parts[1] != "" { // Suffix range: bytes=-N (last N bytes) if suffixLen, err := strconv.ParseInt(parts[1], 10, 64); err == nil { + // RFC 7233: suffix range on empty object or zero-length suffix is unsatisfiable + if totalSize == 0 || suffixLen <= 0 { + w.Header().Set("Content-Range", fmt.Sprintf("bytes */%d", totalSize)) + w.WriteHeader(http.StatusRequestedRangeNotSatisfiable) + return fmt.Errorf("invalid suffix range for empty object") + } if suffixLen > totalSize { suffixLen = totalSize }