Skip to content

gh-144475: Fix a heap buffer overflow in partial_repr#145362

Open
bkap123 wants to merge 3 commits intopython:mainfrom
bkap123:partial-repr
Open

gh-144475: Fix a heap buffer overflow in partial_repr#145362
bkap123 wants to merge 3 commits intopython:mainfrom
bkap123:partial-repr

Conversation

@bkap123
Copy link
Contributor

@bkap123 bkap123 commented Feb 28, 2026

This is a cleaner version of PR #144571 (hence the v2 in the title). I am not exactly sure what happened in #144571 so I would appreciate if anyone could tell me so I don't make the same mistake again.

Here are the changes I made:

  • I added an args and kw local pointer so that both live long enough during the call to repr to prevent a segfault
  • I added an fn local pointer so that repr uses its original state when generating its final representation.
  • I got rid of the error goto and merged it with the done goto as I needed to decrement the reference count of fn, args, and kw, and I found that decrementing them in the done goto was the easiest.
  • I added a test based on @Qanux's original code. I extended it to also check for changes in the fn and kw arguments.

@bkap123 bkap123 requested a review from rhettinger as a code owner February 28, 2026 16:02
Copy link
Member

@aisk aisk left a comment

Choose a reason for hiding this comment

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

Sorry, the approval is by accidant. I don't mean to approve this, just have comments this.

@StanFromIreland StanFromIreland changed the title gh-144475: Fix a heap buffer overflow in partial_repr (v2) gh-144475: Fix a heap buffer overflow in partial_repr Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants