Skip to content

Comments

_struct.c: Fix UB from integer overflow in prepare_s#145158

Merged
gpshead merged 2 commits intopython:mainfrom
StanFromIreland:struct-overflow
Feb 24, 2026
Merged

_struct.c: Fix UB from integer overflow in prepare_s#145158
gpshead merged 2 commits intopython:mainfrom
StanFromIreland:struct-overflow

Conversation

@StanFromIreland
Copy link
Member

Caught by OSS-Fuzz, see https://issues.oss-fuzz.com/issues/466669135.

stan@stanlaptop:~/dev/cpython{main}$ ./python -c 'import struct; struct.Struct("6107082938247334i9221070829382473344q")'
Modules/_struct.c:1681:26: runtime error: signed integer overflow: 6107082938247334 + 9221070829382473344 cannot be represented in type 'long int'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import struct; struct.Struct("6107082938247334i9221070829382473344q")
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: total struct size too long

Skipping news, since there shouldn't be any user-visible change, although I can add one if people prefer.

@gpshead gpshead added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Feb 23, 2026
@gpshead
Copy link
Member

gpshead commented Feb 23, 2026

I suggest adding a one line news entry.

@StanFromIreland
Copy link
Member Author

I suggest adding a one line news entry.

Done, I used the PR number instead of creating an issue.

@gpshead gpshead merged commit fd04005 into python:main Feb 24, 2026
49 checks passed
@miss-islington-app
Copy link

Thanks @StanFromIreland for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 24, 2026
…5158)

Avoid possible undefined behaviour from signed overflow in `struct` module

As discovered via oss-fuzz.
(cherry picked from commit fd04005)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Feb 24, 2026

GH-145162 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Feb 24, 2026
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 24, 2026
…5158)

Avoid possible undefined behaviour from signed overflow in `struct` module

As discovered via oss-fuzz.
(cherry picked from commit fd04005)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Feb 24, 2026

GH-145163 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Feb 24, 2026
gpshead pushed a commit that referenced this pull request Feb 24, 2026
…45158) (#145163)

`_struct.c`: Fix UB from integer overflow in `prepare_s` (GH-145158)

Avoid possible undefined behaviour from signed overflow in `struct` module

As discovered via oss-fuzz.
(cherry picked from commit fd04005)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
gpshead pushed a commit that referenced this pull request Feb 24, 2026
…45158) (#145162)

`_struct.c`: Fix UB from integer overflow in `prepare_s` (GH-145158)

Avoid possible undefined behaviour from signed overflow in `struct` module

As discovered via oss-fuzz.
(cherry picked from commit fd04005)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants