Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Clamp oversized suffix ranges in FileResponse#3307

Merged
Kludex merged 1 commit into
Kludex:mainfrom
jiyujie2006:codex/fix-oversized-suffix-range
May 31, 2026
Merged

Clamp oversized suffix ranges in FileResponse#3307
Kludex merged 1 commit into
Kludex:mainfrom
jiyujie2006:codex/fix-oversized-suffix-range

Conversation

@jiyujie2006

Copy link
Copy Markdown
Contributor

Summary

Clamp suffix byte ranges whose requested length is larger than the file size so FileResponse returns the full representation instead of treating the range as unsatisfiable.

For example, Range: bytes=-1000 against a 526-byte file should produce 206 with Content-Range: bytes 0-525/526.

Root cause

_parse_ranges calculated suffix range starts with file_size - suffix_length. When the suffix length exceeded the file size, that produced a negative start offset, which _parse_range_header rejected with 416.

Checks

  • uv run pytest tests/test_responses.py::test_file_response_suffix_range_larger_than_file -q
  • uv run pytest tests/test_responses.py -k "file_response_range or file_response_suffix_range" -q
  • uv run pytest tests/test_responses.py -q
  • uv run ruff check starlette/responses.py tests/test_responses.py

@jiyujie2006 jiyujie2006 marked this pull request as ready for review May 31, 2026 07:05
@Kludex

Kludex commented May 31, 2026

Copy link
Copy Markdown
Owner

@cubic-dev-ai review this pull request

@cubic-dev-ai

cubic-dev-ai Bot commented May 31, 2026

Copy link
Copy Markdown

@cubic-dev-ai review this pull request

@Kludex I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@Kludex Kludex left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Kludex Kludex changed the title Clamp oversized suffix ranges in FileResponse Clamp oversized suffix ranges in FileResponse May 31, 2026
@Kludex Kludex merged commit 014f0e2 into Kludex:main May 31, 2026
10 checks passed
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