Fix #289 - Python buffer overflow#292
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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) | ||
|
|
Contributor
Author
There was a problem hiding this comment.
I think it's fine. I'm not introducing any new room for errors here.
johnstairs
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.