Skip to content

_interpchannels: ChannelID.__eq__ reads module state from sys.modules without a check #161841

Open

Description

@grgalex

Bug report

Summary

ChannelID comparison looks the extension module up by name in sys.modules and reads its state with PyModule_GetState, without checking that the object found is this extension's module.

If the entry is replaced with a plain module, PyModule_GetState returns NULL without setting an exception, and the comparison returns NULL, which the interpreter reports as a SystemError.

Expected: a normal comparison result, or a clear exception.

Reproducer

import sys, types
import _interpchannels as ch

cid = ch.create()
sys.modules["_interpchannels"] = types.ModuleType("_interpchannels")
cid == 1
SystemError: error return without exception set

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Activity

  1. ZeroIntensity commented on Nov 12, 2026

    @ZeroIntensity
    Member

    Before you file a bunch more AI-found issues: please instead compile your findings into a single gist and create one umbrella issue for them.

  2. grgalex commented on Nov 12, 2026

    @grgalex
    ContributorAuthor

    @ZeroIntensity They are not AI found, there are still people out there doing classic program analysis 😛

    (In this case we are developing a type-checking tool for native extensions)

    I acknowledge that opening separate issues leads to spam. When we find (at least one) more, I will open an umbrella issue and keep adding any future ones there, since in general the underlying root causes are the same.

    Funny story, we had collaborated on my first CPython issue/PR last year (#126555), and in that case I had found the bug with my eyes.

    Now I've evolved to using static analysis (here) and dynamic analysis (#157614). Thankfully not yet opening AI-found issues!

  3. ZeroIntensity commented on Nov 12, 2026

    @ZeroIntensity
    Member

    Ah, okay! But, my comment above still applies, unless you only have a handful of issues (1-8 or so). We've had some issues in the past with people flooding us with a bunch of issue reports all at once. Nothing against you personally, but we don't want to send a message to the AI analyzers that that's okay :)

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions