proxy_cache: reject zero-length and unsatisfiable suffix byte ranges (RFC 9110 §14.1.2) - #975
Open
r7eam wants to merge 1 commit into
Open
proxy_cache: reject zero-length and unsatisfiable suffix byte ranges (RFC 9110 §14.1.2)#975r7eam wants to merge 1 commit into
r7eam wants to merge 1 commit into
Conversation
Per RFC 9110 Section 14.1.2, a suffix-byte-range-spec is unsatisfiable if the suffix-length is zero (e.g. bytes=-0) or if the representation length is zero (e.g. bytes=-5 on a 0-byte body). Previously, parse_range_header returned 0..0 or 10..10 for these cases, treating them as satisfiable single ranges. This caused an unchecked arithmetic underflow (r.end - 1) when formatting Content-Range and corrupted multipart Content-Length calculations. Skip ranges where range.start >= range.end so that empty/unsatisfiable range sets cleanly return RangeType::Invalid (416 Range Not Satisfiable).
r7eam
force-pushed
the
fix-range-unsatisfiable-zero-length
branch
from
August 24, 2026 17:12
11b656b to
4d0d63d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue where suffix byte range requests on zero-length representations (
Range: bytes=-5onContent-Length: 0) or zero-length suffix requests (Range: bytes=-0) were evaluated as satisfiable ranges (0..0or10..10).Details & RFC Conformance
Per RFC 9110 Section 14.1.2:
Previously:
Range: bytes=-5on a 0-byte representation evaluated to0..0, causingrange_header_filterto formatr.end - 1(0usize - 1usize), emittingContent-Range: bytes 0-18446744073709551615/0.Range: bytes=-2,-5), the underflow inflatedcalculate_multipart_lengthto declareContent-Length: 246while delivering 0 payload bytes.Range: bytes=-0on a 10-byte resource evaluated to10..10, emittingContent-Range: bytes 10-9/10.Solution
Inside
parse_range_header, skip ranges whererange.start >= range.end. When all specified ranges are unsatisfiable or skipped,ranges.is_empty()returnsRangeType::Invalid, allowing Pingora to return416 Range Not SatisfiablewithContent-Range: bytes */{length}as required by RFC 9110.Tests
bytes=-0on a 10-byte resource andbytes=-5on a 0-byte resource intest_parse_range.test_range_filter_zero_length_suffixasserting416 Range Not SatisfiablewithContent-Range: bytes */0.