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-158648: Reject code objects whose stacksize overflows co_framesize by Joekrry · Pull Request #159036 · python/cpython

Conversation

@Joekrry

@Joekrry Joekrry commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Fixes gh-158648.

Python/marshal.c reads stacksize from untrusted marshal data with only a >= 0 check. When the code object is constructed, co_framesize = nlocalsplus + stacksize + FRAME_SPECIALS_SIZE is computed as a C int; a stacksize near INT_MAX overflows this, producing a negative co_framesize. That value defeats the stack-space check in _PyThreadState_HasStackSpace _PyThreadState_PushFrame and can move the interpreter's data-stack pointer backwards, corrupting memory rather than failing cleanly.

This adds a bounds check to _PyCode_Validate() — the single validation path shared by marshal, types.CodeType(), and code.replace() — that rejects a stacksize large enough to overflow co_framesize, raising OverflowError instead.

Verified against the PoC in the issue (now raises OverflowError instead of corrupting frame state), plus full test_marshal, test_code, test_sys_settrace, and test_frame runs (all passing).

Sorry, something went wrong.

Uh oh!

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

All reactions
@Joekrry
pythongh-158648: Reject code objects whose stacksize overflows co_fra…
02f8b82
…mesize

  marshal.c reads stacksize from untrusted data with only a >= 0 check.
  A stacksize near INT_MAX overflows the co_framesize computation in
  codeobject.c, producing a negative frame size that corrupts the
  interpreter's data stack instead of failing cleanly. Reject it in
  _PyCode_Validate(), the common validation path used by marshal,
  types.CodeType(), and code.replace().
@Joekrry
Joekrry requested a review from markshannon as a code owner October 8, 2026 18:04
@bedevere-app bedevere-app Bot mentioned this pull request Oct 8, 2026
Marshal Stacksize Integer Overflow leading to Frame Crash #158648
Open
@bedevere-app bedevere-app Bot added the awaiting review label Oct 8, 2026
@picnixz picnixz closed this Oct 8, 2026
@picnixz

picnixz commented Oct 8, 2026

Copy link
Copy Markdown
Member

We did not decide whethet to consider the issue. Please do not open PRs for those cases.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Joekrry
Joekrry deleted the fix-marshal-stacksize-overflow branch October 8, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Marshal Stacksize Integer Overflow leading to Frame Crash

Uh oh!

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

2 participants

@Joekrry @picnixz
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.