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 — readline.c: Missing NULL check on PyLong_FromLong · Issue #154385 · python/cpython

readline.c: Missing NULL check on PyLong_FromLong #154385

New issue
Copy link
New issue
Copy link
Closed
Closed
readline.c: Missing NULL check on PyLong_FromLong#154385
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

Description

@aisk
aisk
opened on Jul 21, 2026
Issue body actions

Bug report

Bug description:

Original gist: https://gist.github.com/devdanzin/60aed55f44fba133ee2d34d46aa8d197

readline.c: Missing NULL check on PyLong_FromLong in setup_readline

Summary

PyLong_FromLong(0L) at lines 1418-1419 stored in begidx/endidx without NULL check. On OOM during module init, readline.get_begidx() does Py_NewRef(NULL) → segfault.

Reproducer

import _testcapi, sys
if "readline" in sys.modules: del sys.modules["readline"]
for n in range(1, 80):
    if "readline" in sys.modules: del sys.modules["readline"]
    _testcapi.set_nomemory(n, 0)
    try:
        import readline
        _testcapi.remove_mem_hooks()
        break
    except MemoryError:
        _testcapi.remove_mem_hooks()
    except ImportError:
        _testcapi.remove_mem_hooks()
    except:
        _testcapi.remove_mem_hooks()
# Assertion: obj != NULL in PyStackRef_FromPyObjectSteal

The original gist said we should check the result of PyLong_FromLong(0L), but I think this is a false positive, because 0 is small int and should not failed while creating a Python int object from it.

However there are other line of code in this file for calling PyLong_FromLong with begidx/endidx withoud check the result:

cpython/Modules/readline.c

Lines 1330 to 1331 in d333e5a

state->begidx = PyLong_FromLong((long) start);
state->endidx = PyLong_FromLong((long) end);

I guess the LLM found a real bug but reported it at the wrong place. Either way, we should fix it.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-154385: Add missing NULL check on PyLong_FromLong in flex_complete in readline.c #154386

Activity

  1. aisk
    added a parent issue on Jul 21, 2026
    • Umbrella issue: bugs found using cpython-review-toolkit #146102
  2. aisk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Jul 21, 2026
  3. aisk
    changed the title [-]# readline.c: Missing NULL check on PyLong_FromLong[/-] [+]readline.c: Missing NULL check on PyLong_FromLong[/+] on Jul 21, 2026
  4. aisk
    added
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 21, 2026
  5. StanFromIreland commented on Oct 25, 2026

    @StanFromIreland
    StanFromIreland
    on Oct 25, 2026
    Member
    More actions

    Fixed in a930e52.

  6. StanFromIreland
    closed this as completedon Oct 25, 2026
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 dirtype-crashA hard crash of the interpreter, possibly with a core dumpA 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

      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.