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-93964: Harden overflow checks before _PyBytes_Resize in compile.c by sweeneyde · Pull Request #94044 · python/cpython

Conversation

@sweeneyde

@sweeneyde sweeneyde commented Jun 21, 2022 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

#93964

The issue was found in 3.10, so it will need to be manually backported there.

  • Issue: Segfault compiling a very large source file #93964

Sorry, something went wrong.

Uh oh!

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

All reactions
@sweeneyde
Harden overflow checks before _PyBytes_Resize in compile.c
72ab0f5
@sweeneyde
sweeneyde requested a review from markshannon as a code owner June 21, 2022 02:49
@bedevere-bot bedevere-bot added the awaiting core review label Jun 21, 2022
@blurb-it
📜🤖 Added by blurb_it.
fa9e69d
@sweeneyde
sweeneyde marked this pull request as draft June 21, 2022 03:43
@sweeneyde
Another test, more comments
e0054bf
@sweeneyde
sweeneyde marked this pull request as ready for review June 21, 2022 04:48
@sweeneyde sweeneyde added the needs backport to 3.11 only security fixes label Jun 21, 2022
@sweeneyde
remove unused variable
e05b51e
markshannon
markshannon reviewed Jun 28, 2022
View reviewed changes
Comment thread Python/compile.c Outdated
Py_ssize_t b_len = PyBytes_GET_SIZE(*bytes);
if (unitsize * logical_length >= b_len - to_add * unitsize) {
// There's not enough room. Double it.
if (b_len > PY_SSIZE_T_MAX / 2) {

@markshannon markshannon Jun 28, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This has the same issue as the backport.
We want to be able to index all code object structures with an int, so you'll need INT_MAX instead of PY_SSIZE_T_MAX and it should be an overflow error, not a memory error.

Sorry, something went wrong.

Uh oh!

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

All reactions

@sweeneyde sweeneyde Jul 26, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

To clarify, we want a_bytecode to be able to have INT_MAX code units, not just INT_MAX bytes, right?

Sorry, something went wrong.

Uh oh!

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

All reactions

@markshannon markshannon Mar 27, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We probably want the smaller amount to avoid risk of overflow. So the length in bytes should be less than INT_MAX.

Sorry, something went wrong.

Uh oh!

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

All reactions
sweeneyde added 4 commits July 25, 2022 23:51
@sweeneyde
Merge remote-tracking branch 'upstream/main' into compile_overflows
cebc41b
@sweeneyde
simplify checks by using b_len/unitsize. use INT_MAX..
75a08cd
@sweeneyde
re-use b_len
7febdc8
@sweeneyde
remove misleading assertion
4a708eb
@sweeneyde sweeneyde mentioned this pull request Sep 2, 2022
Segfault compiling a very large source file #93964
Closed
@arhadthedev

arhadthedev commented Apr 25, 2023

Copy link
Copy Markdown
Member

Is the PR still relevant or some other PR superseded this one?

For merge conflict resolution: touched functions were moved to Python/assemble.c by gh-103277.

cc @iritkatriel

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka serhiy-storchaka added needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes and removed needs backport to 3.11 only security fixes labels May 9, 2024
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@ZeroIntensity ZeroIntensity removed the needs backport to 3.12 only security fixes label May 29, 2025
@github-actions

github-actions Bot commented Apr 11, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 11, 2026
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 bugs and security fixes label May 30, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 5, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 6, 2026
@ambv

ambv commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Rebase review found this PR unportable: the assembler has since moved from compile.c to assemble.c and was rewritten around PyBytesWriter, so this 2022 hardening no longer applies; its issue gh-93964 is already closed. Closing to cull the number of open pull requests. If the hardening is still wanted, please open a new PR against the current assembler rather than reopening this one.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ambv ambv closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon markshannon left review comments

Uh oh!

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

Assignees

No one assigned

Labels

awaiting core review needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

7 participants

@sweeneyde @arhadthedev @ambv @markshannon @serhiy-storchaka @bedevere-bot @ZeroIntensity
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.