fix(storage): correct off-by-one in BlobReader chunked range fetch#16873
Open
Yonghui-Lee wants to merge 1 commit intogoogleapis:mainfrom
Open
fix(storage): correct off-by-one in BlobReader chunked range fetch#16873Yonghui-Lee wants to merge 1 commit intogoogleapis:mainfrom
Yonghui-Lee wants to merge 1 commit intogoogleapis:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request corrects an off-by-one error in the BlobReader.read method where the end parameter for download_as_bytes was incorrectly treated as exclusive. The fix involves subtracting 1 from the fetch_end calculation to align with HTTP Range semantics. Unit tests have been updated to reflect this change, and a new regression test was added. Review feedback suggests clarifying a comment to avoid ambiguity and using more robust mock assertions in the test suite to prevent potential TypeErrors if a mock is not called.
8f81ed7 to
7d3178d
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 off-by-one in
BlobReader.read()that caused every chunked download to request one byte more thanchunk_size.download_as_bytes(end=N)is documented as inclusive (HTTP Range semantics).fileio.py:137passedend = fetch_start + chunk_size, which fetcheschunk_size + 1bytes.Why it was invisible
self._posis incremented by actual bytes consumed.TEST_BINARY_DATA[start:end], end-exclusive), so the test mock and the production code agreed with each other.What changed
google/cloud/storage/fileio.py:end = fetch_start + chunk_size - 1tests/unit/test_fileio.py: rewrote everyread_from_fake_datamock to slice[start:end+1]so it reflects real GCS HTTP Range semantics, and shifted explicitend=Nassertions by -1 (e.g.end=8→end=7).test_read_uses_inclusive_end_rangeto prevent silent regression: withchunk_size=64it asserts the first fetch usesend=63, notend=64.