Security policy¶
Reporting a vulnerability¶
Report privately through GitHub's security advisory form rather than a public issue.
Please include the input that triggers the problem, what happens, and what you expected. A mangled name that reproduces it is worth more than a description.
Threat model¶
This library parses untrusted input by design. A mangled name comes out of a symbol table in a file the calling tool didn't produce and can't vouch for: often malware, a crash dump, or a binary from an unknown source. Anything a crafted name can do to the application reading it is in scope.
Specifically in scope:
- Unbounded memory or CPU use from a short input (algorithmic complexity attacks).
- An exception escaping
demangle()for any string. RecursionErroror stack exhaustion escaping any entry point.- Non-deterministic output for identical input.
- Control characters or other unexpected content reaching output that a caller would reasonably treat as a plain identifier.
Out of scope:
- Incorrect but harmless spellings. Those are conformance bugs: open a normal issue with the mangled name, what the reference demangler prints, and what this prints.
- Resource use above the configured
Limitswhen a caller has deliberately raised them.
Defences¶
demangle()never raises for a name it can't read: it returns the input unchanged. It does raise on a mistake in the call itself, such as alanguageorstylethat doesn't exist, or a name that isn't a string.- Recursion depth, output length, substitution count and input length are all bounded,
with defaults well above anything a real compiler emits, and configurable per call
through
Limits.tests/test_limits.pychecks every registered scheme against the input bound, so a scheme added later is covered too. - Bounds are enforced while a name is read, not checked on the finished result. A short Rust name can ask for millions of bound lifetimes, and by the time an output check ran the string would already have been built.
- Hitting a bound ends the reading. The scheme claimed the name and ran out of the budget the caller set, so the name isn't offered to another scheme, where a laxer one might build a declaration out of the encoding.
- The result cache
demangle()keeps is bounded in bytes as well as entries, so a stream of long hostile names cannot grow it past about 100 MB. KeyboardInterrupt,SystemExitandMemoryErrorare never swallowed by the best-effort paths. They mean the process is in trouble, not that a name is malformed.- The library is safe to call from several threads.
tests/test_concurrency.pychecks that every thread agrees with the single-threaded answer character for character, over every scheme's corpus, and CI runs it on a free-threaded build where there's no GIL to hide a shared mutable parser. - The package has no runtime dependencies, so it brings no supply chain with it. A test enforces that.
- The property-based suite runs the parsers against arbitrary text, mangling-alphabet text, arbitrary bytes, every truncation of a known-good name, and inputs constructed to defeat a naive parser.
Measured worst case¶
How much work one symbol can cause is measured, for every scheme, by growing a repeated
unit until it reaches the input bound and recording wall time and peak allocation.
Apart from the one case below, nothing is superlinear. The worst shape in the package
is a Swift name at the longest the default max_input allows (64K characters), and
it's linear in the input.
The exception is quadratic, and bounded. Every Itanium <prefix> is a substitution
candidate and each entry holds the whole prefix, so N components record O(N²)
characters without any single one crossing max_output. The characters the table
records are capped at sixteen times the output bound, a hundred times what the largest
of the 217,730 Itanium symbols in a stock Ubuntu 24.04 records.
The fuzzers (Fuzzing and the reference
demanglers) check on each name that
nothing but a DemanglingError escapes, that the tree renders exactly what the text
path spelled in both styles, and that no substitution-table sentinel reaches a builder.
The mutation runs are under an address-space cap, so a runaway allocation reports the
name that caused it rather than being killed.
How a release is built, and how to check one¶
- Releases are published from GitHub Actions through PyPI
Trusted Publishing. There is no PyPI API
token, in the repository or anywhere else, for anyone to steal; the upload is authorised
by a short-lived OIDC token that only
release.yml, running in thepypienvironment of this repository, can obtain, and that environment waits for a maintainer's approval. - Every file on PyPI carries an attestation that names this repository and that workflow.
pypi-watch.ymlchecks that several times an hour and opens an issue if PyPI ever serves a file without one, or lists a second owner. PyPI shows the attestation under Verified details, and it can be checked from a shell:
$ python -m pip install pypi-attestations
$ python -m pypi_attestations verify pypi --repository https://github.com/r0ny123/demangle \
pypi:demangle-0.7.0-py3-none-any.whl
OK: demangle-0.7.0-py3-none-any.whl
- Releases after 0.9.4 also carry a GitHub build provenance attestation for every file, which needs nothing from PyPI to check:
$ gh attestation verify demangle-X.Y.Z-py3-none-any.whl --repo r0ny123/demangle \
--signer-workflow r0ny123/demangle/.github/workflows/release.yml
- Before the approval,
tools/check_artifacts.pyopens the sdist and every wheel and fails the release unless each file in them is a tracked file of the tagged commit with the same bytes, the metadata the build writes, or one of the compiled extensions. A.pthfile, an extra module or a new dependency stops it there. The run's summary lists what changed since the last release. - The pure wheel is reproducible:
uv buildat the release tag, with the hatchling thatuv.lockpins, gives thepy3-none-anyfile on PyPI byte for byte, so its SHA-256 can be compared with the one PyPI lists. - Nothing is resolved while a release is built, or anywhere in CI. uv is installed from
tools/uv-requirements.txtand everything else fromuv.lock, each file checked against a hash that is in the repository, and the build runs without a network. A new release of a build or test dependency reaches a workflow only through a reviewed change to those files, which Dependabot proposes once the release has been public for a week. - Every GitHub Action is pinned to a commit, workflows are given a read-only token unless a job says otherwise, and no workflow runs code from a fork with a secret or a writable token.
- The documentation site and its playground load no script, stylesheet, image or frame
from another host. The Pyodide runtime the playground runs on is served by the site,
each file checked against a pinned SHA-256 when the site is built; tests hold both.
Every page carries a Content Security Policy that refuses other hosts, for the scripts
the theme's bundle would still fetch: a polyfill in a browser too old for
ResizeObserver, and the loaders of features this site doesn't use. The playground page also carries a Content Security Policy that allows only its own scripts and styles, with no inline code, so a pasted or linked symbol can't run as script even if a rendering bug let it into the page.
Supported versions¶
| Version | Supported |
|---|---|
| 0.9.x | yes |
| < 0.9 | no |
Until 1.0, security fixes land on the latest released minor version only. There is no long-term support branch and no backporting; upgrading to the current minor version is the fix.