Skip to content

Fix #289 - Python buffer overflow#292

Merged
naegelejd merged 1 commit into
mainfrom
naegelejd/fix-289
Jun 25, 2026
Merged

Fix #289 - Python buffer overflow#292
naegelejd merged 1 commit into
mainfrom
naegelejd/fix-289

Conversation

@naegelejd

Copy link
Copy Markdown
Contributor

No description provided.

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.

Pull request overview

Fixes the Python binary writer crash reported in #289 by making single-byte writes safe at exact buffer boundaries, and adds focused unit/regression coverage for buffer-boundary behavior across core serializers.

Changes:

  • Replaced unchecked single-byte writes with a new CodedOutputStream.write_byte() that flushes when the buffer has no remaining capacity.
  • Updated serializers and protocol termination code paths to use write_byte() instead of the previous unchecked path.
  • Added a comprehensive pytest suite exercising buffer-boundary flush behavior and regressions for stream/optional/union serializer framing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tooling/internal/python/static_files/_binary.py Introduces a capacity-aware write_byte() and routes key single-byte call sites through it to avoid boundary overflows.
python/tests/test_coded_stream.py Adds buffer-boundary and regression tests (including end-to-end repro of #289) for coded streams and serializers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +143 to +147
def write_byte(self, value: int) -> None:
if (len(self._buffer) - self._offset) < 1:
self.flush()
self._write_byte_unchecked(value)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it's fine. I'm not introducing any new room for errors here.

Comment thread python/tests/test_coded_stream.py
@naegelejd naegelejd merged commit 96672f9 into main Jun 25, 2026
15 checks passed
@naegelejd naegelejd deleted the naegelejd/fix-289 branch June 25, 2026 19:07
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.

3 participants