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 — `sys.audit(0)` aborts due to an assertion in debug build · Issue #126018 · python/cpython

sys.audit(0) aborts due to an assertion in debug build #126018

New issue
Copy link
New issue
Copy link
Closed
Closed
sys.audit(0) aborts due to an assertion in debug build#126018
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesextension-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-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

Description

@devdanzin
devdanzin
opened on Oct 26, 2024
Issue body actions

Crash report

What happened?

There is an assert in sysmodule.c that makes the interpreter abort when calling sys.audit with a non-string value in debug builds:

cpython/Python/sysmodule.c

Line 522 in f6cc7c8

assert(PyUnicode_Check(args[0]));

Python 3.14.0a1+ (heads/main:c5b99f5c2c, Oct 26 2024, 12:35:53) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.audit(9)
python: ./Python/sysmodule.c:522: sys_audit: Assertion `PyUnicode_Check(args[0])' failed.
Aborted (core dumped)

This assert seems completely unnecessary, as the code that runs the hooks (which only triggers if there is some hook registered) will raise an exception if the first argument to sys.audit isn't a string:

Python 3.14.0a1+ (heads/remove_sysaudit_assert:ba8ac4d398, Oct 26 2024, 19:45:11) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.addaudithook(lambda *args: None)
>>> sys.audit(9)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    sys.audit(9)
    ~~~~~~~~~^^^
TypeError: expected str for argument 'event', not int

I'll submit a trivial PR removing this assert.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux, Windows

Output from running 'python -VV' on the command line:

Python 3.14.0a1+ (heads/main:c5b99f5c2c, Oct 26 2024, 12:35:53) [GCC 13.2.0]

Linked PRs

  • gh-126018: Avoid aborting due to unnecessary assert in sys.audit #126020
  • [3.13] gh-126018: Avoid aborting due to unnecessary assert in sys.audit (GH-126020) #126042

Activity

  1. devdanzin
    added
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Oct 26, 2024
  2. Eclips4
    added
    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 Oct 26, 2024
  3. picnixz
    added
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    on Oct 26, 2024
  4. picnixz commented on Oct 26, 2024

    @picnixz
    picnixz
    on Oct 26, 2024
    Member
    More actions

    Ok, 3.12 is actually not affected:

    cpython/Python/sysmodule.c

    Lines 499 to 514 in 67b2701

    if (!should_audit(tstate->interp)) {
    Py_RETURN_NONE;
    }
    PyObject *auditEvent = args[0];
    if (!auditEvent) {
    _PyErr_SetString(tstate, PyExc_TypeError,
    "expected str for argument 'event'");
    return NULL;
    }
    if (!PyUnicode_Check(auditEvent)) {
    _PyErr_Format(tstate, PyExc_TypeError,
    "expected str for argument 'event', not %.200s",
    Py_TYPE(auditEvent)->tp_name);
    return NULL;
    }

  5. picnixz
    removed
    3.12only security fixesonly security fixes
    on Oct 26, 2024
  6. devdanzin commented on Oct 27, 2024

    @devdanzin
    devdanzin
    on Oct 27, 2024
    MemberAuthor
    More actions

    Ok, 3.12 is actually not affected:

    Hmm. The assert was deliberately added in #108965. @vstinner, what do you think about the proposal to remove the eager assert for non-string argument to sys.audit?

  7. JelleZijlstra
    added a commit that references this issue on Oct 27, 2024

    gh-126018: Avoid aborting due to unnecessary assert in `sys.audit` (#…

    80eec52
  8. miss-islington
    added a commit that references this issue on Oct 27, 2024

    pythongh-126018: Avoid aborting due to unnecessary assert in `sys.aud…

    e0eeb70
  9. JelleZijlstra
    added a commit that references this issue on Oct 27, 2024

    [3.13] gh-126018: Avoid aborting due to unnecessary assert in `sys.au…

    e4157f0
  10. picnixz commented on Oct 27, 2024

    @picnixz
    picnixz
    on Oct 27, 2024
    Member
    More actions

    Closing since completed and backported. Thanks!

  11. picnixz
    closed this as completedon Oct 27, 2024
  12. picnixz
    added a commit that references this issue on Dec 8, 2024

    pythongh-126018: Avoid aborting due to unnecessary assert in `sys.aud…

    353994f
  13. ebonnal
    added a commit that references this issue on Jan 12, 2025

    pythongh-126018: Avoid aborting due to unnecessary assert in `sys.aud…

    3a9bc3f
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

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesextension-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-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.