Skip to content

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

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

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

Conversation

@brijkapadia
Copy link
Copy Markdown
Contributor

@brijkapadia brijkapadia commented Feb 7, 2026

@python-cla-bot
Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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)

@brijkapadia
Copy link
Copy Markdown
Contributor Author

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 <10796600+picnixz@users.noreply.github.com>
@dr-carlos
Copy link
Copy Markdown
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 :)

@brijkapadia
Copy link
Copy Markdown
Contributor Author

brijkapadia 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.
…ions (pythonGH-144824)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
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.
…h item (python#145282)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>

---------

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
@brijkapadia brijkapadia 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.