Skip to content

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

Closed
bkap123 wants to merge 231 commits intopython:mainfrom
bkap123:fix-functools_partial_repr_bug
Closed

gh-144475: Fix a heap buffer overflow in partial_repr#144571
bkap123 wants to merge 231 commits intopython:mainfrom
bkap123:fix-functools_partial_repr_bug

Conversation

@bkap123
Copy link
Contributor

@bkap123 bkap123 commented Feb 7, 2026

@bkap123 bkap123 requested a review from rhettinger as a code owner February 7, 2026 16:19
@python-cla-bot
Copy link

python-cla-bot bot commented Feb 7, 2026

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@bedevere-app
Copy link

bedevere-app bot commented Feb 7, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@picnixz
Copy link
Member

picnixz commented Feb 7, 2026

Please:

  • add regression tests and check that the test failed before your change
  • remove blank lines in NEWS

@picnixz
Copy link
Member

picnixz commented Feb 7, 2026

By the way, @dr-carlos already suggested to open a PR. It is polite to ask them if they want to contribute themselves. As such, I'm going to close this one unless they are fine with you making the PR (we don't really want people "sniping" work of others)

@bkap123
Copy link
Contributor Author

bkap123 commented Feb 7, 2026

Thanks for the feedback. I missed that @dr-carlos suggested to fix it.

I’m happy to close this PR if @dr-carlos is already working on it.

Co-authored-by: Bénédikt Tran <[email protected]>
@dr-carlos
Copy link
Contributor

Thanks for the feedback. I missed that @dr-carlos suggested to fix it.

I’m happy to close this PR if @dr-carlos is already working on it.

Hi, thanks for asking!
I'm happy for you to continue with the PR :)

@bkap123
Copy link
Contributor Author

bkap123 commented Feb 8, 2026

Here are the changes I made:

  • I added a kw local pointer, as a similar segfault happens for keywords
  • 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.
    Update: I changed the goto logic to reduce repetitive calls to Py_DECREF
  • I added a test based on @Qanux's original code in issue heap-buffer-overflow in functools.partial.__repr__() #144475. I extended it to also check for changes in the fn and kw arguments.

serhiy-storchaka and others added 23 commits February 28, 2026 08:31
… Segment (pythonGH-145216)

Remove the tp_clear slots and make Segment members read-only.

Also add tests for reference loops involving GraphemeBreakIterator
and Segment.
Remove PyThread_type_lock (now uses PyMutex internally).

Add new benchmark options:
- work_inside/work_outside: control work inside and outside the critical section to vary contention levels
- num_locks: use multiple independent locks with threads assigned round-robin
- total_iters: fixed iteration count per thread instead of time-based, useful for measuring fairness
- num_acquisitions: lock acquisitions per loop iteration
- random_locks: acquire random lock each iteration

Also return elapsed time from benchmark_locks() and switch lockbench.py to use argparse.
Co-authored-by: Pieter Eendebak <[email protected]>

---------

Co-authored-by: Pieter Eendebak <[email protected]>
@bkap123 bkap123 deleted the fix-functools_partial_repr_bug branch February 28, 2026 13:41
@hugovk hugovk removed request for a team, berkerpeksag and freakboy3742 February 28, 2026 14:02
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.