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 — Various UB warnings found by UBSan · Issue #148286 · python/cpython

Various UB warnings found by UBSan #148286

New issue
Copy link
New issue
Copy link
Open
Open
Various UB warnings found by UBSan#148286
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@StanFromIreland
StanFromIreland
opened on Apr 9, 2026
Issue body actions

Bug report

Bug description:

These were all found by UBSan in our CI (it just hasn't been complaining about them). They need to be individually checked, some may be false positives.

# Objects/object.c:97:5: runtime error: member access within null pointer of type 'PyThreadState' (aka 'struct _ts')
null:Objects/object.c

In test_memoryview:

# Objects/memoryobject.c:3032:15: runtime error: load of value 2, which is not a valid value for type 'bool'
bool:Objects/memoryobject.c

In test_ctypes:

# Modules/_ctypes/cfield.c:644:1: runtime error: left shift of 1 by 63 places cannot be represented in type 'int64_t' (aka 'long')
shift-base:Modules/_ctypes/cfield.c

# Modules/_ctypes/cfield.c:640:1: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
signed-integer-overflow:Modules/_ctypes/cfield.c

In test_zstd:

# Modules/_zstd/decompressor.c:598:56: runtime error: applying non-zero offset 18446744073709551615 to null pointer
pointer-overflow:Modules/_zstd/decompressor.c
# Modules/_io/stringio.c:350:24: runtime error: addition of unsigned offset to 0x7fd01ec25850 overflowed to 0x7fd01ec2584c
pointer-overflow:Modules/_io/stringio.c
# Objects/bytesobject.c:1190:25: runtime error: applying zero offset to null pointer
pointer-overflow:Objects/bytesobject.c

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-148286: Run test_capi and test_faulthandler on GHA UBSan #151274
  • gh-148286: Fail on new UB in CI #148168
  • gh-148286: Remove invalid test in test_decodeescape #153187
  • [3.15] gh-148286: Remove invalid test in test_decodeescape (GH-153187) #153204
  • gh-148286: Fix UB in ZstdDecompressor.unused_data when a frame is decompressed in one call #153258
  • [3.15] gh-148286: Fix UB in ZstdDecompressor.unused_data when a frame is decompressed in one call (GH-153258) #153644
  • [3.14] gh-148286: Fix UB in ZstdDecompressor.unused_data when a frame is decompressed in one call (GH-153258) #153645
  • gh-148286: Fix undefined behaviour in the ctypes bit field accessors #154912
  • gh-148286: Fix undefined behaviour in io.StringIO.read() after an overseek #154913
  • gh-148286: Fix undefined behaviour in per-thread refcount merging #154915
  • gh-148286: Track JIT-allocated memory with Valgrind client requests #154926

Activity

  1. StanFromIreland
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Apr 9, 2026
  2. StanFromIreland
    added a commit that references this issue on Apr 9, 2026

    gh-148286: Fail when new UB is found by CI UBSan (#148168)

    ade914b
  3. picnixz
    self-assigned this
    on Apr 11, 2026
  4. picnixz commented on Apr 11, 2026

    @picnixz
    picnixz
    on Apr 11, 2026
    Member
    More actions

    I can confirm the memoryview() UB:

    Objects/memoryobject.c:3032:15: runtime error: load of value 2, which is not a valid value for type 'bool'
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/memoryobject.c:3032:15
    Objects/memoryobject.c:3032:15: runtime error: load of value 2, which is not a valid value for type 'bool'
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/memoryobject.c:3032:15
    

    The others look random and probably are so.

  5. picnixz commented on Apr 11, 2026

    @picnixz
    picnixz
    on Apr 11, 2026
    Member
    More actions

    So the memoryview UBSan is more severe than I expected (see #83870 for the past history as well). I will create a new issue.

    Reacted by Stan Ulbrych
  6. picnixz
    removed their assignment
    on Apr 11, 2026
  7. picnixz commented on Apr 11, 2026

    @picnixz
    picnixz
    on Apr 11, 2026
    Member
    More actions

    For now, I will not investigate the others because I wasn't able to catch them with clang (but it may be other build configurations).

    Reacted by Stan Ulbrych
  8. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-148286: Fail when new UB is found by CI UBSan (python#148168)

    ebe6d29
  9. StanFromIreland
    added 5 commits that reference this issue on Jul 6, 2026

    gh-148286: Remove invalid test in `test_decodeescape` (#153187)

    8477652

    [3.15] gh-148286: Remove invalid test in `test_decodeescape` (GH-153187…

    8d21592

    gh-148286: Fix UB in `ZstdDecompressor.unused_data` when a frame is d…

    adebb68

    [3.14] gh-148286: Fix UB in `ZstdDecompressor.unused_data` when a fra…

    b0842ed

    [3.15] gh-148286: Fix UB in `ZstdDecompressor.unused_data` when a fra…

    9108488
  10. matthiasgoergens commented on Jul 30, 2026

    @matthiasgoergens
    matthiasgoergens
    on Jul 30, 2026
    Contributor
    More actions

    While working through the Modules/_ctypes/cfield.c and Modules/_io/stringio.c entries on this list I ran the suppression file against some configurations CI does not currently build, and turned up one more UB site that is not on the list above. Recording it here rather than opening a separate issue, since it is the same class of thing.

    Python/uniqueid.c:185, free-threaded builds only. _PyObject_MergePerThreadRefcounts() does refcnt << _Py_REF_SHARED_SHIFT where refcnt is a per-thread delta and is almost always -1. Fix in #154915.

    The reason it is not on the list is structural: the sanitizer matrix in .github/workflows/build.yml pairs UBSan only with free-threading: false, so Python/uniqueid.c is never built under UBSan. It is not an obscure path either — the first line of output from ./python -c pass on a --disable-gil --with-undefined-behavior-sanitizer build is the UBSan report, raised during interpreter startup, and it recurs from gc_collect_main on every collection. Over the full suite with all suppressions disabled: 1762 reports, 529 test failures across 61 files, going to zero with the fix.

    Two smaller findings from the same sweep, in case they are useful:

    • local-bounds is not part of the undefined group that --with-undefined-behavior-sanitizer enables, so it runs nowhere today. I built with it enabled and ran the full suite: zero findings, including no false positives from the trailing variable-length array idiom, which was the thing I expected to cause noise. It looks like a free check to add.
    • float-divide-by-zero, also not in the undefined group, produces exactly one hit: Modules/expat/xmlparse.c:869, in vendored libexpat, which deliberately relies on IEEE-754 +inf and says so in a comment, with an assert(newTotal > 0) above guaranteeing it is not NaN. Technically UB in C, intentional in practice — so this one probably is not worth enabling without excluding expat.

    Happy to open separate issues for either if that is preferred.

  11. matthiasgoergens
    added 5 commits that reference this issue on Jul 30, 2026

    pythongh-148286: Fix undefined behaviour in io.StringIO.read() after …

    addc87f

    pythongh-148286: Fix undefined behaviour in per-thread refcount mergi…

    a4cda41

    pythongh-148286: Track JIT-allocated memory with Valgrind client requ…

    f3dec60

    pythongh-148286: Fix undefined behaviour in the ctypes bit field acce…

    721f6ce

    pythongh-148286: Fix undefined behaviour in per-thread refcount mergi…

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.