python / python/cpython

Potential Integer Overflow in mark_stacks function

Open
#132,771 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.13 3.14 interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

There is a potential signed integer overflow in the expression:
https://github.com/python/cpython/blob/132b6bc98f47a4d897dead8635b5a50a0baee485/Objects/frameobject.c#L1365
This occurs in the loop:
https://github.com/python/cpython/blob/132b6bc98f47a4d897dead8635b5a50a0baee485/Objects/frameobject.c#L1329
len is derived from a Py_SIZE cast, and it can possibly be INT_MAX:
https://github.com/python/cpython/blob/132b6bc98f47a4d897dead8635b5a50a0baee485/Objects/frameobject.c#L1728-L1730
It means that sum can theoretically exceed INT_MAX if len is near the limit, triggering undefined behavior due to signed integer overflow.

Linked PRs
  • gh-132773
  • gh-132830

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Objects/frameobject.c at mark_stacks, especially the loop around line 1329 and the expression near line 1365; trace how len is derived at lines 1728-1730. Done means the calculation no longer permits signed overflow when len approaches INT_MAX, with the behavior checked against the linked PRs gh-132773 and gh-132830.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.