Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144100: Fix crash for POINTER(str) used in ctypes argtypes#144108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@VanshAgarwal24036
Copy link
Contributor

@VanshAgarwal24036VanshAgarwal24036 commentedJan 21, 2026
edited by bedevere-appbot
Loading

It fixes a crash inctypes that occur when a deprecatedPOINTER(str) type was used inargtypes.

When such a pointer type was encountered during argument conversion,ctypes would hit an internal assertion and abort the interpreter in debug builds.
This PR replaces the assertion with proper error handling and raises a Python exception instead.

@VanshAgarwal24036

This comment was marked as resolved.

@VanshAgarwal24036
Copy link
ContributorAuthor

@vstinner This is my proposed solution if you have time please review it.

Comment on lines 478 to 479
withself.assertWarns(DeprecationWarning):
BadType=ctypes.POINTER("BugTrigger")
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to avoid deprecated code path. You should be able to use:

Suggested change
withself.assertWarns(DeprecationWarning):
BadType=ctypes.POINTER("BugTrigger")
classBadType(ctypes._Pointer):
# _type_ is not defined on purpose
pass

Comment on lines 481 to 488
ifos.name=="nt":
libc=ctypes.WinDLL("kernel32.dll")
func=libc.GetCurrentProcessId
else:
libc=ctypes.CDLL(None)
func=libc.getpid

func.argtypes= (BadType,)
Copy link
Member

Choose a reason for hiding this comment

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

You can use the Python C API:

Suggested change
ifos.name=="nt":
libc=ctypes.WinDLL("kernel32.dll")
func=libc.GetCurrentProcessId
else:
libc=ctypes.CDLL(None)
func=libc.getpid
func.argtypes= (BadType,)
func=ctypes.pythonapi.Py_GetVersion
func.argtypes= (BadType,)

ptr.set_type(c_int)
self.assertIs(ptr._type_,c_int)

classTestPointerStringProto(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to add the test to the end of PointersTestCase, instead of adding a new test case.

importgc
importsys
importunittest
importos
Copy link
Member

Choose a reason for hiding this comment

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

This import can be removed with my proposed code.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinnervstinner added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsJan 26, 2026
@vstinnervstinner merged commit8f45925 intopython:mainJan 26, 2026
55 checks passed
@miss-islington-app
Copy link

Thanks@VanshAgarwal24036 for the PR, and@vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJan 26, 2026
…ythonGH-144108)(cherry picked from commit8f45925)Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>Co-authored-by: Victor Stinner <vstinner@python.org>
@miss-islington-app
Copy link

Sorry,@VanshAgarwal24036 and@vstinner, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 8f459255eba2b6639f1912e5c5e318a7cdafada1 3.13

@bedevere-app
Copy link

GH-144244 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelJan 26, 2026
@bedevere-app
Copy link

GH-144245 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelJan 26, 2026
@vstinner
Copy link
Member

Merged. Thanks for the fix.

@VanshAgarwal24036
Copy link
ContributorAuthor

Thanks for guidance and review

@VanshAgarwal24036VanshAgarwal24036 deleted the gh-144100-ctypes-pointer-protol branchJanuary 26, 2026 12:36
vstinner added a commit that referenced this pull requestJan 26, 2026
…H-144108) (#144244)gh-144100: Fix crash for POINTER(str) used in ctypes argtypes (GH-144108)(cherry picked from commit8f45925)Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner approved these changes

Assignees

@vstinnervstinner

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@VanshAgarwal24036@vstinner

[8]ページ先頭

©2009-2026 Movatter.jp