Skip to content

fix: redact upload-source repr, close the stream, and validate range offsets - #716

Merged
ffumero2003 merged 2 commits into
masterfrom
fix-python-low-audit-upload-source
Nov 21, 2026
Merged

ffumero2003 merged 2 commits into
masterfrom
fix-python-low-audit-upload-source

Conversation

@ffumero2003

Copy link
Copy Markdown
Contributor

Context

Improve upload-source handling for in-memory data, temporary checksum streams, and local file ranges.

Root cause

The byte-source representation included payload bytes, checksum calculation did not close its opened stream, and local file range offsets were not checked against file bounds.

Changes

  • Represent byte sources using their length rather than their contents.
  • Close checksum streams after successful reads or errors.
  • Reject offsets outside the file while allowing a zero-length range at EOF.
  • Turn existing expected-failure cases into regression tests and cover logging, error cleanup, and valid range boundaries.

Verification

  • Each issue was reproduced on master before the fix and passed afterward.
  • Unit suite: v3 1,267 passed, v2 1,272 passed, v1 1,317 passed, and v0 1,157 passed (with expected skips and xfails).
  • Ruff and nox -vs towncrier_check passed.
  • nox -vs lint passed Ruff but its static tests failed on two pre-existing strict XPASS cases for the corrected SUPPORT and README documentation. The same failures were reproduced in a clean archive of master.

Refs #711

@ffumero2003 ffumero2003 self-assigned this Nov 21, 2026
@ffumero2003
ffumero2003 requested a review from goanpeca November 21, 2026 22:51
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Byte-source representations now report content length and object ID instead of payload bytes. Local-file ranges reject offsets below zero or beyond the file size. Checksum calculation closes the opened stream when the context exits. Tests cover these behaviors and valid range boundaries.

Merge Risk: Minimal · up to e7092

This change stops byte-source representations from exposing upload payloads, closes checksum streams after reads, and rejects invalid local file range offsets. It has focused tests and no outstanding concrete merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the three main changes: redacting the upload-source repr, closing the stream, and validating range offsets. These match the raw summary and the PR objectives, so the title is fully rel…
Description check Passed The description states the context, root cause, changes, and verification steps. Each item matches the file-level summary and the PR objectives, so the description is clearly related to the changeset.
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 names the three main changes: redacting the upload-source repr, closing the stream, and validating range offsets. These match the raw summary and the PR objectives, so the title is fully 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: f2e34314-fbb1-4bcc-83a4-1cb70a5b73ff
Commits

Reviewing files that changed from the base of the PR and between be0814d and e7092af.

Files selected for processing: 4

  • b2sdk/_internal/transfer/outbound/upload_source.py
  • changelog.d/+upload-source-safety.fixed.md
  • test/unit/stream/test_regression_streams.py
  • test/unit/stream/test_upload_source_safety.py

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

@ffumero2003
ffumero2003 merged commit 973ad35 into master Nov 21, 2026
29 checks passed
@ffumero2003
ffumero2003 deleted the fix-python-low-audit-upload-source branch November 21, 2026 23:33
ffumero2003 added a commit that referenced this pull request Nov 21, 2026
…722)

Merging the low-severity fixes (#716, #719) converted known-defect tests
to ordinary assertions but left test.known_defect imports unused, failing
ruff (F401) on master. Import only the names each module still uses.

Refs #711
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