GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-156939: Fix two bugs in PyBytesWriter by vstinner · Pull Request #158404 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Sep 29, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fix PyBytesWriter_Format() error handling: restore the writer to its previous state on error. Add an unit test injecting MemoryError.

Fix PyBytesWriter_FinishWithSize() to return an empty bytearray when use_bytearray is set and size is 0, instead of always returning an empty bytes object.

Fix test_capi.test_bytes: always check writer finish result type, to make sure that _PyBytesWriter_CreateByteArray() always create bytearray objects.

  • Issue: C API: Detect buffer overflow in PyBytesWriter #156939

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner @claude
pythongh-156939: Fix two bugs in PyBytesWriter
ed1785f
Fix PyBytesWriter_Format() error handling: restore the writer to its
previous state on error. Add an unit test injecting MemoryError.

Fix PyBytesWriter_FinishWithSize() to return an empty bytearray when
use_bytearray is set and size is 0, instead of always returning an
empty bytes object.

Fix test_capi.test_bytes: always check writer finish result type, to
make sure that _PyBytesWriter_CreateByteArray() always create
bytearray objects.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vstinner vstinner added the skip news label Sep 29, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Sep 29, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Sep 29, 2026
C API: Detect buffer overflow in PyBytesWriter #156939
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 29, 2026
@vstinner vstinner added the needs backport to 3.15 bugs and security fixes label Sep 29, 2026
@vstinner

vstinner commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

The "Android aarch64" job failed with a download error: Command "curl -Lf --retry 5 --retry-all-errors -o /Users/runner/work/cpython/cpython/cross-build/downloads/xz-5.4.6-1-aarch64-linux-android.tar.gz https://github.com/beeware/cpython-android-source-deps/releases/download/xz-5.4.6-1/xz-5.4.6-1-aarch64-linux-android.tar.gz" returned exit status 56. I restarted the job.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner removed the type-feature A feature request or enhancement label Sep 29, 2026
@vstinner
vstinner merged commit 24ea85a into python:main Sep 29, 2026
100 of 106 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner deleted the fix_writer branch September 29, 2026 12:50
@miss-islington-app

miss-islington-app Bot commented Sep 29, 2026

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Sep 29, 2026
@miss-islington-app

miss-islington-app Bot commented Sep 29, 2026

Copy link
Copy Markdown

Sorry, @vstinner, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 24ea85a4c2998b36cc4c83ff0505678d178b49d1 3.15
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned vstinner Sep 29, 2026
@bedevere-app

bedevere-app Bot commented Sep 29, 2026

Copy link
Copy Markdown

GH-158409 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Sep 29, 2026
hugovk pushed a commit that referenced this pull request Sep 30, 2026
@vstinner @claude
[3.15] gh-156939: Fix two bugs in PyBytesWriter (#158404) (#158409)
3740f74
* gh-156939: Fix two bugs in PyBytesWriter (#158404)

Fix PyBytesWriter_Format() error handling: restore the writer to its
previous state on error. Add an unit test injecting MemoryError.

Fix PyBytesWriter_FinishWithSize() to return an empty bytearray when
use_bytearray is set and size is 0, instead of always returning an
empty bytes object.

Fix test_capi.test_bytes: always check writer finish result type, to
make sure that _PyBytesWriter_CreateByteArray() always create
bytearray objects.

Co-authored-by: Claude Opus 4.6 <[email protected]>
(cherry picked from commit 24ea85a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@vstinner vstinner

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@vstinner
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.