s3/transfermanager: fix panic in concurrentReader when len(p) is smaller than cap(p) - #3388
Open
islishude wants to merge 3 commits into
Open
s3/transfermanager: fix panic in concurrentReader when len(p) is smaller than cap(p)#3388islishude wants to merge 3 commits into
islishude wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a slice-bounds panic in feature/s3/transfermanager’s concurrentReader.read by ensuring all read-window calculations and slicing are bounded by len(p) (per io.Reader contract), not cap(p).
Changes:
- Replace
cap(p)withlen(p)for empty-buffer detection, max part selection, and safe slicing inconcurrentReader.read. - Add a regression test covering both previously-panicking paths: reading from an already-buffered chunk and from a newly received chunk.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| feature/s3/transfermanager/concurrent_reader.go | Bounds all indexing/slicing in read to len(p) to prevent panics with short slices. |
| feature/s3/transfermanager/concurrent_reader_test.go | Adds regression coverage to ensure short len(p) with larger cap(p) does not panic and does not advance buffered chunk state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wty-Bryant
reviewed
Jun 1, 2026
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
This fixes a panic in
concurrentReader.readwhen the caller passes a slice wherelen(p) < cap(p).The reader was using
cap(p)to:p[index:]was safe to sliceThat is not safe for an
io.Reader, because reads must be bounded bylen(p), notcap(p).In this case, the old logic could treat an offset as valid and then panic with a slice-bounds error when evaluating
p[index:].Changes
cap(p)withlen(p)inconcurrentReader.readTesting
TestConcurrentReaderReadUsesSliceLenForBounds