Skip to content

Python extractor loses lib-dynload path when _json is a built-in module #23293

Todo

Description

@konard

CodeQL CLI 2.27.5, Python extractor 7.2.1, runs on Ubuntu 26.04 with the system CPython 3.14.4. The Python analyzer completes, but each worker prints Failed to find dynload path. The finder then has no directory with which to recognize dynamically loaded standard-library modules such as _ctypes.

The affected CI job logs the existing /usr/lib/python3.14/lib-dynload directory in the Python search path directly before the warning.

Reproducer

On Ubuntu 26.04 with system Python 3.14, download the 2.27.5 extractor's imp.py to the current directory, then run:

/usr/bin/python3.14 -S - <<'PY'
import importlib.util
import os
import sysconfig
import imp

print(imp.__file__)
print(importlib.util.find_spec('_json').origin)
print(importlib.util.find_spec('_ctypes').origin)
print(sysconfig.get_config_var('DESTSHARED'))
print(os.path.dirname(imp.find_module('_json')[1]))
PY

I reproduced this with the Ubuntu python3.14-minimal, libpython3.14-minimal, and libpython3.14-stdlib packages at 3.14.4-1ubuntu0.2. _json is built-in, _ctypes resolves to the real lib-dynload directory, and DESTSHARED reports the directory. The last call raises TypeError because the bundled imp.find_module('_json') returns (None, None, ('', '', 6)). With a CPython build where _json is a shared extension, the same call succeeds.

Workaround and suggested change

Run the extractor with a supported Python whose _json is a shared extension. For Actions, actions/setup-python can put that Python first on PATH. CODEQL_EXTRACTOR_PYTHON_OPTION_PYTHON_EXECUTABLE_NAME=python3 selects it for the tracer and LGTM_PYTHON_SETUP_VERSION=3 selects Python 3 for setup discovery. A downstream verification run passed on CPython 3.14.10 with zero dynload warnings and extracted repository Python files.

In BuiltinFinder.__init__, consider using sysconfig.get_config_var('DESTSHARED') when it points to an existing directory, with the existing extension lookup as a fallback. Add a regression case with a built-in _json and a separate native _ctypes extension. That would keep extension classification working when the same Python version is built differently by a distribution.

The same verification run still prints one caught /bin/sh: 1: python2: not found line. This comes from site_flag calling executable(3) before its gzip check. set_available_versions invokes both interpreter names through a shell even with Python 3 selected. A direct subprocess.check_call(executable_name(version) + ["-c", "pass"]) can catch FileNotFoundError or CalledProcessError locally while preserving the tracer’s -S option. This is independent of native-module directory detection.

Activity

  1. tausbn commented on Dec 1, 2026

    @tausbn
    Contributor

    Thank you for reporting this. This part of the Python extractor has always been a bit of a hack (relying on _json having certain properties that, as it turns out, are not always the case).

    The suggested fix sounds good to me. I'll create a PR for it.

  2. mrankara955-lang commented on Dec 1, 2026

    @mrankara955-lang

    Hck

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions