Skip to content

Undefined behavior in struct.unpack #96735

Description

@kumaraditya303

Reproducer:

import struct
struct.unpack('!q', b'\xff\xff\xff\xff\xff\xff\xff\xff')

Error:

Modules/_struct.c:842:15: runtime error: left shift of 72057594037927935 by 8 places cannot be represented in type 'long long int'

Compiler options:

./configure -C --with-pydebug --with-address-sanitizer --with-undefined-behavior-sanitizer 

Python version: Python 3.12.0a0 (heads/main:30cc1901efa, Sep 10 2022, 10:14:58) [GCC 9.4.0] on linux

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.11only security fixes
    type-crashA hard crash of the interpreter, possibly with a core dump
    3.12only security fixes
    on Sep 10, 2022
  2. kumaraditya303 commented on Sep 10, 2022

    @kumaraditya303
    ContributorAuthor
  3. mdickinson commented on Sep 10, 2022

    @mdickinson
    Member

    @kumaraditya303 Thanks; this should be an easy fix.

  4. self-assigned this
    on Sep 10, 2022
  5. added a commit that references this issue on Sep 25, 2022
  6. mdickinson commented on Sep 25, 2022

    @mdickinson
    Member

    Fixed for 3.12 in #96739. I agree with @matthiasgoergens that it's not worth fixing in 3.10 and 3.11, because the issue doesn't manifest itself in release builds, where -fwrapv is used.

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

Metadata

Metadata

Assignees

Labels

3.10 (EOL)end of life3.11only security fixes3.12only security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errortype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions