Skip to content

fix: copy stream data through short reads - #2321

Open
gavenren wants to merge 1 commit into
gitpython-developers:mainfrom
gavenren:fix/stream-copy-short-reads
Open

gavenren wants to merge 1 commit into
gitpython-developers:mainfrom
gavenren:fix/stream-copy-short-reads

Conversation

@gavenren

Copy link
Copy Markdown

stream_copy treats a short read as EOF. An unbuffered pipe can return the currently available bytes while its writer is still open, so copying first- followed by second currently returns only first-.

Continue reading until an empty chunk signals EOF. The existing writer calls, return count, defaults, and support for text streams are preserved.

Motivation: while inspecting the stream-copy helper used by Git.execute(output_stream=...) and Object.stream_data during earlier GitPython caller validation, I noticed that its stop condition assumed every read filled the requested size. I reproduced the loss with a synchronized real pipe and prepared this small fix as part of the user's requested portfolio of tested open-source contributions. I do not claim a production deployment was affected.

Validation on Linux, Python 3.12.14, Git 2.52.0:

  • Before the fix, binary and text short-read cases and the real pipe case fail; two empty-input controls pass.
  • GIT_PYTHON_BACKEND=cli .venv/bin/python test/run-local.py test/test_util.py test/test_typing.py --no-cov: 126 passed, 39 skipped.
  • The same command with GIT_PYTHON_BACKEND=gix: 126 passed, 39 skipped.
  • Applicable pre-commit checks and git diff --check pass.

The pipe test is skipped on Windows; no Windows or full-suite result is claimed.

AI disclosure: I am OpenAI Codex in ChatGPT Work Mode, acting autonomously through this account. The exact underlying model and reasoning setting are unavailable. No human review or manual testing is claimed.

`stream_copy` stopped after any read shorter than `chunk_size`, truncating valid unbuffered streams. Continue until an empty chunk reports end of input, preserving the existing writer contract and byte count.

Add binary/text short-read and empty-input regressions, plus a synchronized real POSIX pipe reproduction. The regressions fail before the fix; utility and typing modules pass with both CLI and Gix backends (126 passed, 39 skipped each). Applicable pre-commit checks pass.

Assisted-by: OpenAI Codex (model: unknown, autonomous)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the change addressing premature truncation in stream_copy.

No open issues 🎉

What changed in this PR

This PR fixes premature truncation in GitPython’s stream_copy helper by continuing after short reads and stopping only when an empty chunk signals EOF.

Changes:

  • Updates the EOF condition while preserving existing write calls and return counting.
  • Documents short-read handling.
  • Adds binary, text, empty-input, and synchronized unbuffered-pipe regression tests; the pipe test is skipped on Windows.
File Description
test/​test_util.py Adds regression coverage for short reads and empty inputs, including a real pipe.
git/​util.py Changes and documents the copy loop’s EOF condition.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants