Skip to content

range: a suffix range longer than the content selects all of it - #4026

Merged
jknack merged 1 commit into
jooby-project:mainfrom
wleeaf:byte-range-long-suffix
Oct 26, 2026
Merged

jknack merged 1 commit into
jooby-project:mainfrom
wleeaf:byte-range-long-suffix

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

ByteRange.parse computes the start of a suffix range (bytes=-N) as contentLength - N. When N is larger than the content, the start is negative. For a 1000-byte file, Range: bytes=-2000 gives a SingleByteRange that starts at -1000. Netty then fails with IllegalArgumentException: position : -1000 (expected: >= 0) in DefaultFileRegion, and the client gets a broken response (a 400 logged after the headers, then a closed connection).

RFC 9110 section 14.1.3 says: "If the selected representation is shorter than the specified suffix-length, the entire representation is used." So the request should get 206 with Content-Range: bytes 0-999/1000. Media players and download managers send suffix ranges to read trailing metadata, and they don't know the length in advance.

The start is now Math.max(0, contentLength - end). bytes=-0 still gives 416, because the start is then past the end.

The new case in ByteRangeTest.byteRange (bytes=-300 on 200 bytes: start 0, bytes 0-199/200) fails without the change (expected: <0> but was: <-100>). mvn -pl jooby test passes, and spotless:check reports no violations in the changed files.

@jknack jknack added the bug label Oct 26, 2026
@jknack jknack added this to the 4.5.5 milestone Oct 26, 2026
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (e64c771) to head (6991cbe).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4026      +/-   ##
============================================
- Coverage     94.18%   94.16%   -0.02%     
+ Complexity     6656     6653       -3     
============================================
  Files           432      432              
  Lines         20897    20897              
  Branches       2096     2096              
============================================
- Hits          19682    19678       -4     
- Misses          762      764       +2     
- Partials        453      455       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jknack
jknack merged commit b682179 into jooby-project:main Oct 26, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants