Files
seaweedFS/weed
Chris Lu 383c2e3b41 fix: handle range requests on empty objects (size=0) (#7963)
* fix: handle range requests on empty objects (size=0)

Range requests on empty objects were incorrectly being rejected with:
'invalid range start for ...: 0 >= 0'

The validation logic used 'startOffset >= totalSize' which failed when
both were 0, incorrectly rejecting valid range requests like bytes=0-1535
on 0-byte files.

Fix: Added special case handling before validation to properly return
416 Range Not Satisfiable for any range request on an empty object,
per RFC 7233.

Fixed at two locations (lines 873 and 1154) in s3api_object_handlers.go

* refactor: return 404 for directory objects, not 416

Per S3 semantics, GET requests on directory paths (without trailing "/")
should return 404 Not Found, not try to serve them as objects.

Updated fix to:
1. Check if entry.IsDirectory and return 404 (S3-compliant)
2. Only return 416 for true empty files (size=0, not directory)

This matches AWS S3 behavior where directories don't exist as objects
unless they're explicit directory markers ending with "/".

* reduce repeated info

* refactor: move directory check before range branching

This ensures that any Range header (including suffix ranges like bytes=-N)
on a directory path (without trailing slash) returns 404 (ErrNoSuchKey)
instead of potentially returning 416 or attempting to serve as an object.

Applied to both streamFromVolumeServers and streamFromVolumeServersWithSSE.

* refactoring
2026-01-04 13:55:33 -08:00
..
2026-01-04 11:26:21 -08:00
2025-10-13 18:05:17 -07:00
2026-01-04 11:40:42 -08:00
2024-06-25 09:18:11 -07:00
2026-01-04 00:38:53 -08:00
2024-02-14 08:26:38 -08:00
2026-01-01 19:20:59 -08:00
2026-01-04 11:40:42 -08:00