Unsafe pointer dereference from unchecked Python integer in Tk initialization#9548
Open
barttran2k wants to merge 1 commit intopython-pillow:mainfrom
Conversation
…d python i In `_tkinit`, `PyLong_AsVoidPtr(arg)` converts an arbitrary Python object to a `void*` pointer which is then cast to `Tcl_Interp*` and passed to `TkImaging_Init`. If `PyLong_AsVoidPtr` fails (returns NULL and sets an error), or if the caller passes an arbitrary integer value, the code proceeds to dereference it without any validation, potentially leading to a crash or arbitrary memory access. Affected files: _imagingtk.c Signed-off-by: Trần Bách <45133811+barttran2k@users.noreply.github.com>
radarhere
approved these changes
Apr 7, 2026
Member
|
As a general note, our README does ask that you e-mail security problems to us privately. https://github.com/python-pillow/pillow#report-a-vulnerability
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
In
_tkinit,PyLong_AsVoidPtr(arg)converts an arbitrary Python object to avoid*pointer which is then cast toTcl_Interp*and passed toTkImaging_Init. IfPyLong_AsVoidPtrfails (returns NULL and sets an error), or if the caller passes an arbitrary integer value, the code proceeds to dereference it without any validation, potentially leading to a crash or arbitrary memory access.Severity:
mediumFile:
src/_imagingtk.cSolution
Check the return value of
PyLong_AsVoidPtrfor errors (NULL with exception set) before passinginterptoTkImaging_Init. Add:if (interp == NULL && PyErr_Occurred()) { return NULL; }Changes
src/_imagingtk.c(modified)Testing