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-156204: Guard recursion in PyErr_GivenExceptionMatches by BHUVANSH855 · Pull Request #156205 · python/cpython

Conversation

@BHUVANSH855

@BHUVANSH855 BHUVANSH855 commented Aug 21, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Fixes issue gh-156204.

PyErr_GivenExceptionMatches in Python/errors.c recursively unpacks tuple targets without recursion checks, causing native C stack exhaustion and a SIGSEGV when given deeply nested exception tuples.

This change:

  • Guards recursion in PyErr_GivenExceptionMatches via Py_EnterRecursiveCall() and Py_LeaveRecursiveCall().
  • Adds a _testcapi.err_givenexceptionmatches() helper and a regression test in Lib/test/test_exceptions.py.
  • Adds a blurb NEWS entry.

Verified: with Python/errors.c reverted to the pre-fix version the new test segfaults; with the fix it passes.

Sorry, something went wrong.

Uh oh!

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

All reactions
@BHUVANSH855
pythongh-156204: Guard recursion in PyErr_GivenExceptionMatches
df43d6a
@BHUVANSH855
BHUVANSH855 requested a review from iritkatriel as a code owner August 21, 2026 18:59
@bedevere-app bedevere-app Bot added the awaiting review label Aug 21, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Aug 21, 2026
PyErr_GivenExceptionMatches crashes with SIGSEGV on deeply nested tuple targets #156204
Closed
@BHUVANSH855
pythongh-156204: Safely skip ctypes test on mobile/wasm and reduce tu…
d0d8595
…ple depth
iritkatriel
iritkatriel reviewed Aug 21, 2026
View reviewed changes
Comment thread Lib/test/test_exceptions.py Resolved

Uh oh!

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

iritkatriel
iritkatriel reviewed Aug 21, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-08-21-18-49-12.gh-issue-156204.ZusA7e.rst Resolved

Uh oh!

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

@BHUVANSH855
pythongh-156204: address review feedback
b6be6c5
@BHUVANSH855
BHUVANSH855 requested a review from ZeroIntensity as a code owner August 21, 2026 20:16
@BHUVANSH855
BHUVANSH855 requested a review from iritkatriel August 21, 2026 20:17
@read-the-docs-community

read-the-docs-community Bot commented Aug 21, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34178190 | 📁 Comparing b6be6c5 against main (999a046)

  🔍 Preview build  

2 files changed
± c-api/exceptions.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

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

ZeroIntensity
ZeroIntensity reviewed Aug 21, 2026
View reviewed changes
Comment thread Doc/c-api/exceptions.rst Resolved

Uh oh!

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

@BHUVANSH855
pythongh-156204: drop docs change
170d3c9
@BHUVANSH855
BHUVANSH855 requested a review from ZeroIntensity August 21, 2026 20:29
iritkatriel
iritkatriel reviewed Aug 24, 2026
View reviewed changes
Comment thread Modules/_testcapi/exceptions.c Resolved

Uh oh!

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

Comment thread Python/errors.c Resolved

Uh oh!

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

@BHUVANSH855
pythongh-156204: convert test helper to Argument Clinic
12ce58f
@BHUVANSH855
BHUVANSH855 requested a review from iritkatriel September 24, 2026 14:12
@BHUVANSH855
pythongh-156204: remove comment
e7c80b9
@iritkatriel

iritkatriel commented Sep 26, 2026

Copy link
Copy Markdown
Member

Looks like some test is failing.

All reactions

Sorry, something went wrong.

Uh oh!

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

BHUVANSH855 added 2 commits September 27, 2026 10:35
@BHUVANSH855
Merge remote-tracking branch 'upstream/main' into fix-err-given-excep…
a4fc16a
…tion-matches-recursion
@BHUVANSH855
Merge branch 'main' into fix-err-given-exception-matches-recursion
6765ff2
@BHUVANSH855

BHUVANSH855 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

Looks like some test is failing.

hi, the failing checks were unrelated to this PR, as the PR was stale form some days, so I updated the branch and synced it to the current main.
Hope this time no check fails.

All reactions

Sorry, something went wrong.

Uh oh!

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

ZeroIntensity
ZeroIntensity reviewed Sep 27, 2026
View reviewed changes
Comment thread Python/errors.c Resolved

Uh oh!

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

Comment thread Modules/_testcapi/exceptions.c Resolved

Uh oh!

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

Comment thread Python/errors.c Resolved

Uh oh!

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

@BHUVANSH855
pythongh-156204: report recursion overflow as unraisable
141b181
@BHUVANSH855
BHUVANSH855 requested a review from ZeroIntensity September 27, 2026 18:49
ZeroIntensity
ZeroIntensity reviewed Sep 28, 2026
View reviewed changes
Comment thread Python/errors.c Resolved

Uh oh!

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

ZeroIntensity
ZeroIntensity approved these changes Sep 28, 2026
View reviewed changes

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM. I'll give Irit some time to take another look before merging, and I'll also run the buildbots in the meantime to make sure that the recursive test doesn't fail on some weird platforms.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Sep 28, 2026
@ZeroIntensity ZeroIntensity added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 28, 2026
@bedevere-bot

bedevere-bot commented Sep 28, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit 141b181 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F156205%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 28, 2026
@ZeroIntensity ZeroIntensity added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 2, 2026
@ZeroIntensity
ZeroIntensity merged commit 20d5e67 into python:main Oct 2, 2026
144 of 150 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 2, 2026
@miss-islington-app

miss-islington-app Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thanks @BHUVANSH855 for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 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 commented Oct 2, 2026

Copy link
Copy Markdown

GH-158622 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 Oct 2, 2026
@bedevere-app

bedevere-app Bot commented Oct 2, 2026

Copy link
Copy Markdown

GH-158623 is a backport of this pull request to the 3.14 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.14 bugs and security fixes label Oct 2, 2026
ZeroIntensity pushed a commit that referenced this pull request Oct 2, 2026
@miss-islington @BHUVANSH855
[3.14] gh-156204: Guard recursion in PyErr_GivenExceptionMatches (G…
a9eeb9f
…H-156205) (GH-158623)

(cherry picked from commit 20d5e67)

Co-authored-by: Bhuvansh <[email protected]>
@bedevere-bot

bedevere-bot commented Oct 2, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows Server 2022 NoGIL 3.14 (tier-1) has failed when building commit a9eeb9f.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1717/builds/1803) and take a look at the build logs.
  4. Check if the failure is related to this commit (a9eeb9f) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1717/builds/1803

Summary of the results of the build (if available):

==

Click to see traceback logs
Note: switching to 'a9eeb9f2f517046fc1fae061dee0e6856a414077'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at a9eeb9f2f51 [3.14] gh-156204: Guard recursion in `PyErr_GivenExceptionMatches` (GH-156205) (GH-158623)
Switched to and reset branch '3.14'

Could Not Find C:\bbarea\3.14.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\*.pyc
The system cannot find the file specified.
Could Not Find C:\bbarea\3.14.itamaro-win64-srv-22-aws.x64.nogil\build\PCbuild\python*.zip

Kill <WorkerThread #1 running test=test_ssl pid=10028 time=12.7 sec> process
Kill <WorkerThread #2 running test=test_math pid=12212 time=1 min 23 sec> process
Kill <WorkerThread #3 running test=test_platform pid=11020 time=5.1 sec> process
Kill <WorkerThread #4 running test=test_mmap pid=10216 time=50.5 sec> process
Kill <WorkerThread #5 running test=test_generated_cases pid=4316 time=1.9 sec> process
Kill <WorkerThread #6 running test=test_tarfile pid=2016 time=1 min 19 sec> process
Kill <WorkerThread #7 running test=test.test_multiprocessing_spawn.test_processes pid=8764 time=1 min 35 sec> process
Kill <WorkerThread #8 running test=test_linecache pid=16160 time=2.1 sec> process
Kill <WorkerThread #9 running test=test_complex pid=11812 time=746 ms> process
Kill <WorkerThread #10 running test=test_sys pid=1820 time=3.9 sec> process
Kill <WorkerThread #11 running test=test_statistics pid=12164 time=1 min 33 sec> process
Kill <WorkerThread #12 running test=test_traceback pid=10472 time=45.0 sec> process
Kill <WorkerThread #13 running test=test_lzma pid=3568 time=3.6 sec> process
Kill <WorkerThread #14 running test=test_dataclasses pid=3984 time=1.8 sec> process
Kill <WorkerThread #15 running test=test_json pid=12988 time=33.7 sec> process
Kill <WorkerThread #16 running test=test_weakref pid=11724 time=13.4 sec> process
Kill <WorkerThread #18 running test=test_frame pid=17040 time=1.5 sec> process
Kill <WorkerThread #19 running test=test_free_threading pid=8940 time=1 min 35 sec> process
Kill <WorkerThread #20 running test=test_compileall pid=6524 time=46.6 sec> process

Could Not Find C:\bbarea\3.14.itamaro-win64-srv-22-aws.x64.nogil\build\PCbuild\python*.zip

Expanding reachable commits in commit graph: 138558
Expanding reachable commits in commit graph: 171624, done.
All reactions

Sorry, something went wrong.

Uh oh!

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

@BHUVANSH855
BHUVANSH855 deleted the fix-err-given-exception-matches-recursion branch October 3, 2026 05:46
This was referenced Oct 3, 2026
Doc: Py_EnterRecursiveCall uses C stack space, not a call counter #158643
Closed
gh-158643: Doc: document that Py_EnterRecursiveCall uses C stack, not a counter #158644
Merged
ZeroIntensity added a commit that referenced this pull request Oct 11, 2026
@miss-islington @BHUVANSH855 @ZeroIntensity
[3.15] gh-156204: Guard recursion in PyErr_GivenExceptionMatches (G…
ae21cb7
…H-156205) (GH-158622)

(cherry picked from commit 20d5e67)

Co-authored-by: Bhuvansh <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity ZeroIntensity approved these changes
@iritkatriel iritkatriel Awaiting requested review from iritkatriel iritkatriel is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

4 participants

@BHUVANSH855 @iritkatriel @bedevere-bot @ZeroIntensity
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.