Skip to content

Reject inverted single-byte Range like bytes=5-4 - #3389

Merged
Kludex merged 3 commits into
Kludex:mainfrom
nikolauspschuetz:fix-range-header-inverted-single-byte
Aug 8, 2026
Merged

Kludex merged 3 commits into
Kludex:mainfrom
nikolauspschuetz:fix-range-header-inverted-single-byte

Conversation

@nikolauspschuetz

@nikolauspschuetz nikolauspschuetz commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #3388.

FileResponse._parse_range_header only rejected ranges where start > end, but bytes=5-4 parses to the empty half-open range (5, 5) and slipped past that guard, producing a malformed 206 (Content-Length: 0, a backwards Content-Range) instead of a 400. bytes=10-5 was already caught (it parses to (10, 6)); the missed case is the off-by-one boundary where end + 1 == start.

The guard is now start >= end. A genuine one-byte request bytes=5-5 parses to (5, 6) and is unaffected.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Review in cubic

_parse_range_header only rejected ranges where start > end, but
"bytes=5-4" parses to the empty half-open range (5, 5), which slips
past that guard and produces a malformed 206 response (Content-Length 0,
a backwards Content-Range) instead of a 400. Reject empty ranges with
start >= end; a genuine one-byte request like "bytes=5-5" parses to
(5, 6) and is unaffected.

Adds tests for the inverted range (400) and the valid one-byte range
(206).
@Kludex
Kludex marked this pull request as ready for review August 8, 2026 08:53
@Kludex
Kludex enabled auto-merge (squash) August 8, 2026 08:55
@Kludex
Kludex merged commit 78ae82c into Kludex:main Aug 8, 2026
11 checks passed
@codspeed

codspeed Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 148 untouched benchmarks


Comparing nikolauspschuetz:fix-range-header-inverted-single-byte (bfb9733) with main (c1d6eda)

Open in CodSpeed

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.

FileResponse accepts inverted single-byte Range like bytes=5-4

2 participants