Skip to content

Keep negative-size range-stream reads within the selected range - #677

Merged
ffumero2003 merged 3 commits into
masterfrom
fix-stream-c46-range-read-minus-one
Nov 19, 2026
Merged

ffumero2003 merged 3 commits into
masterfrom
fix-stream-c46-range-read-minus-one

Conversation

@ffumero2003

Copy link
Copy Markdown
Contributor

Summary

Reading a range stream with a negative size (e.g. read(-1)) returned bytes past the end of the configured range, because the negative size was passed straight to the inner stream. This clamps a negative size to the remaining range length.

Changes

  • Clamp negative-size reads in RangeOfInputStream (b2sdk/_internal/stream/range.py).
  • Clarify the bounded-read behavior in the docstring.
  • Add regression tests for the range cases.

Verification

  • python -m pytest test/unit/stream — 7 passed
  • towncrier changelog validation passed

Supersedes the stale draft #633 (same one-line clamp); #633 can be closed.

@ffumero2003 ffumero2003 self-assigned this Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

RangeOfInputStream.read now handles negative sizes like None and reads only the remaining configured range. Unit tests cover reads after partial consumption, reads at the range end, and zero-length ranges. A changelog entry records the fix.

Merge Risk: Minimal · up to df4f9

Negative-size reads on a range stream no longer return bytes beyond the configured range. The change is small, covered by unit tests, and carries no identified merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: negative-size reads on a range stream are kept within the selected range. The raw summary and description both describe clamping negative sizes in RangeOfInputStream.…
Description check Passed The description explains the bug (negative sizes such as read(-1) passed to the inner stream, returning bytes past the configured range), the clamping fix, the docstring clarification, the regression …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: negative-size reads on a range stream are kept within the selected range. The raw summary and description both describe clamping negative sizes in RangeOfInputStream.read to the remaining range length, so the title matches the changeset.

Full details: Description check

Explanation

The description explains the bug (negative sizes such as read(-1) passed to the inner stream, returning bytes past the configured range), the clamping fix, the docstring clarification, the regression tests, and the verification steps. It is directly related to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b3370395-d683-4f0c-8ee5-66862fc8f4c0
Commits

Reviewing files that changed from the base of the PR and between afb0a7d and df4f9c8.

Files selected for processing: 3

  • b2sdk/_internal/stream/range.py
  • changelog.d/+range-read-negative-size.fixed.md
  • test/unit/stream/test_finding_c46_range.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@ffumero2003
ffumero2003 merged commit 564785a into master Nov 19, 2026
29 checks passed
@ffumero2003
ffumero2003 deleted the fix-stream-c46-range-read-minus-one branch November 19, 2026 19:27
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.

1 participant