Skip to content

Undefined Behavior triggered in dictobject #136660

Closed
@marler8997

Description

@marler8997

Bug report

Bug description:

When building with ubsan enabled, an unaligned access error gets triggered in dictobject.c. I triggered this on linux x86_64 when interpreting the following script:

import argparse
parser = argparse.ArgumentParser()

Here's the ubsan error message:

thread 15767 panic: load of misaligned address 0x386b491 for type 'PyDictUnicodeEntry *', which requires 8 byte alignment
Objects/dictobject.c:1504:21: 0x2916e0e in dictresize (cpython/Objects/dictobject.c)
                    memcpy(newentries, oldentries, numentries * sizeof(PyDictUnicodeEntry));
                    ^

Adding logs around the call to memcpy reveals that oldentries contains an unaligned value, but, numentries is also 0, which, means most implementations would probably do what the caller expects, namely, nothing.

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions