Conversation
ParseRange computed length = end - start + 1 from the raw end and only clamped it to the file size afterwards. A huge end overflows that: bytes=0-9223372036854775807 gives a negative length, which the clamp does not catch, so the download answers 206 with a broken Content-Range and Content-Length and no body. bytes=1-9223372036854775807 overflows start+length instead. Clamp the end to size-1 first, as net/http does.
acodercat
requested review from
Pangjiping,
hittyt and
ninan-nn
as code owners
September 30, 2026 06:16
Pangjiping
reviewed
Sep 30, 2026
Pangjiping
left a comment
Collaborator
There was a problem hiding this comment.
Code review: 1 high-severity finding (verified against commit cd454ab).
utils.go and utils_windows.go each had their own copy of httpRange and ParseRange, identical apart from the previous fix, which only went into the non-Windows one. Windows builds still computed the length from the raw end and could overflow. The parser has nothing platform specific, so keep one copy in range.go and drop both duplicates.
This branch has not been deployed
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
ParseRangecomputeslength = end - start + 1from the end value the client sent, and only clamps it to the file size afterwards. A very large end overflows before the clamp runs:bytes=0-9223372036854775807gives a negative length. The clamp (start+length > size) never fires for a negative value, so the download responds 206 with a brokenContent-RangeandContent-Length, andsends no body.
bytes=1-9223372036854775807giveslength = MaxInt64. This timestart+lengthis what overflows, and it gets past the clamp the same way.Both the regular download and the isolated-session download go through this parser.
The fix clamps the end to
size-1before computing the length, which is also the order net/http uses:r.length = min(j, size-1) - i + 1. I usedmininstead of anifsoParseRangestays under thegocognit limit. For any input that didn't overflow before, the result is the same as it used to be.
The parser had a second, identical copy in utils_windows.go that the first commit missed. The second commit moves httpRange and ParseRange into a platform-independent range.go and removes both copies, so Windows
builds get the fix too.
Testing
I added four cases to the
TestParseRangetable: end past size, end at MaxInt64, an end that makes start+length overflow, and a start past size. The two overflow cases fail on main.I also checked that nothing else changed. I compared the old and new parser on 200k random headers covering all three range forms, multiple ranges, size 0, and values at and around the file size, and they
returned identical results. That comparison test isn't committed.
go test ./pkg/...,go vet ./...and golangci-lint are clean, and darwin/windows build.Breaking Changes
Checklist