Skip to content

fix(fs): reject zero-length suffix byte ranges - #2460

Merged
erikdubbelboer merged 1 commit into
valyala:masterfrom
kevin9327:fix-zero-suffix-byte-range
Oct 5, 2026
Merged

erikdubbelboer merged 1 commit into
valyala:masterfrom
kevin9327:fix-zero-suffix-byte-range

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

ParseByteRange accepts the suffix range bytes=-0 and returns startPos = contentLength, endPos = contentLength - 1. The FS handler then replies 206 Partial Content with an empty body and an invalid Content-Range:

fs := &fasthttp.FS{Root: ".", AcceptByteRange: true}
// GET /LICENSE with "Range: bytes=-0"
// => 206, Content-Range: bytes 1158-1157/1158, Content-Length: 0

RFC 9110 §14.1.1 only treats a suffix range as satisfiable when its suffix-length is non-zero, so this should be 416 Range Not Satisfiable. Every other unsatisfiable range already gets that response through the error path. ParseByteRange now returns an error for a zero suffix length.

Added bytes=-0 to TestParseByteRangeError; it fails without the change. go test . and go vet . pass.

@erikdubbelboer
erikdubbelboer merged commit 741bd41 into valyala:master Oct 5, 2026
8 checks passed
@erikdubbelboer

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants