Skip to content

Do not read past the end of a tuple subclass with a larger __len__ - #10359

Open
Parsiffall1 wants to merge 2 commits into
python-pillow:mainfrom
Parsiffall1:fix-tuple-subclass-len-path
Open

Parsiffall1 wants to merge 2 commits into
python-pillow:mainfrom
Parsiffall1:fix-tuple-subclass-len-path

Conversation

@Parsiffall1

Copy link
Copy Markdown

Fixes #10358.

Changes proposed in this pull request:

  • PyPath_Flatten() uses the length from PyObject_Length(), which calls a subclass's __len__. For tuples it then read items with the unchecked PyTuple_GET_ITEM(), so a tuple subclass that reported a larger length read past the end of the tuple and crashed. This uses PyTuple_GetItem() instead, which raises IndexError, matching what already happens for list subclasses.
  • Adds a test with a tuple subclass whose __len__ is larger than its contents.

@radarhere

Copy link
Copy Markdown
Member

Note that I'm not sure if the issue needs to be fixed.

@akx

akx commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Same class of issue as #10198, #10055. PyPath_Flatten is also presumably then also prone to crash if a member of the sequence mutates the sequence (since assign_item_to_array can end up calling back to user coercion code) (which is the thing #10055 tries to fix).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageDraw.arc() segfaults on a tuple subclass whose __len__ is too large

3 participants