Skip to content

Keep negative-size range reads within the selected range - #633

Draft
Kayvan-Zahiri wants to merge 1 commit into
Backblaze:masterfrom
Kayvan-Zahiri:codex/bound-negative-range-reads
Draft

Kayvan-Zahiri wants to merge 1 commit into
Backblaze:masterfrom
Kayvan-Zahiri:codex/bound-negative-range-reads

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

RangeOfInputStream.read(-1) passes the negative size directly to its underlying stream, which reads through the underlying EOF rather than stopping at the selected range boundary. This also consumes data from an empty or already exhausted range. For example, wrapping BytesIO(b"0123456789") with offset 2 and length 3 returns b"23456789" rather than b"234".

Treat all negative sizes as an unbounded read of the remaining selected range, matching the existing read(None) behavior. Add 14 tests through the exported v3 class covering negative/default/large/zero/bounded reads, partial reads, empty ranges, EOF, and positions. Includes the required changelog fragment.

Validation on Python 3.12:

  • Before the fix: 7 new cases failed, 7 controls passed.
  • Full v3 unit suite: 907 passed, 64 skipped, 81 subtests passed.
  • Stream suites under API v0/v1/v2: 17 passed each.
  • Full repository Ruff lint, changed-file formatting, static header test, and dependency license check passed.
  • Full formatting check reports only untouched noxfile.py; the same discrepancy is present in HEAD.

No hosted B2 integration or full Python/OS matrix run. AI-assisted contribution; maintainer review pending.

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