Skip to content

GHSA-pph8-gcv7-4qj5 RUSTSEC-2025-0020

PyO3 Risk of buffer overflow in `PyString::from_object`

Low crates.io
Severity
0.0 / 10
Low · CVSS 4.0
Exploit chance (EPSS)
—
No score published
Known exploited
No
Not in CISA's catalog
Weakness
CWE-125 Out-of-bounds Read
Fix
0.24.1
Upgrade pyo3 to this version or later

Description

PyString::from_object took &str arguments and forwarded them directly to the Python C API without checking for terminating nul bytes. This could lead the Python interpreter to read beyond the end of the &str data and potentially leak contents of the out-of-bounds read (by raising a Python exception containing a copy of the data including the overflow).

In PyO3 0.24.1 this function will now allocate a CString to guarantee a terminating nul bytes. PyO3 0.25 will likely offer an alternative API which takes &CStr arguments.

Affected versions

crates.io

PackageVulnerableFixed in
pyo3
>= 0.1.0, < 0.24.1
0.24.1
pyo3
>= 0.0.0-0, < 0.24.1
0.24.1

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

pyo3 crates.io → 0.24.1

cargo
cargo update -p pyo3 --precise 0.24.1

Severity breakdown

CVSS 4.0 0.0

CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:P

Attack vector
Network
Attack complexity
Low
Attack requirements
Present
Privileges required
None
User interaction
None
Confidentiality (vulnerable system)
None
Integrity (vulnerable system)
None
Availability (vulnerable system)
Low
Confidentiality (subsequent systems)
None
Integrity (subsequent systems)
None
Availability (subsequent systems)
None
Exploit maturity
Proof of concept

Weakness

CWE-125: Out-of-bounds Read

The product reads data past the end, or before the beginning, of the intended buffer.

How to prevent it
  • Implementation: Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. To reduce the likelihood of introducing an out-of-bounds read, ensure that you validate and ensure correct calculations for any length argument, buffer size calculation, or offset. Be especially careful of relying on a sentinel (i.e. special character such as NUL) in untrusted inputs.
  • Architecture and Design: Use a language that provides appropriate memory abstractions.

References

Timeline

  1. Published
  2. Last updated by the source
AdvisorySeverityWhy it's related
GHSA-chgr-c6px-7xpp
PyO3 has a missing `Sync` bound on `PyCFunction::new_closure` closures
Medium Also affects pyo3
GHSA-36hh-v3qg-5jq4
PyO3 has an Out-of-bounds Read in `nth` / `nth_back` for `PyList` and `PyTuple` iterators
High Also affects pyo3
GHSA-47qc-857f-7w7f
PyO3 has type confusion when accessing data from sublasses of subclasses of native types with `abi3` feature
High Also affects pyo3
GHSA-vxcf-c7mx-pg53
Build corruption when using `PYO3_CONFIG_FILE` environment variable
Medium Also affects pyo3
GHSA-6jgw-rgmm-7cv6
PyO3 has a risk of use-after-free in `borrowed` reads from Python weak references
Medium Also affects pyo3
GHSA-2vx6-fcw6-hpr6
Reference counting error in pyo3
Medium Also affects pyo3
GHSA-9v9v-9qvf-h2hj
Pillow: Heap over-read in WMF/EMF rendering via 16-bit dimension truncation (Windows builds)
High Same weakness, CWE-125
GHSA-v9pv-5gc8-w2m6
Pillow multi-frame loaders can reuse stale native image storage after mode transitions
Critical Same weakness, CWE-125
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor