# PyO3 missing Sync bound in PyCFunction new_closure

Source: https://junglewise.ai/threats/pyo3-missing-sync-bound-in-pycfunction-new-closure-37dd6bc7  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-06-12. Updated: 2026-06-12  
License: CC BY 4.0 with a link back

Severity: medium · CVSS 6.3 · Published 2026-06-12

PyO3, a library used to bridge Rust and Python code, contains a thread-safety flaw in how it handles certain background functions (closures). Because these functions were not properly restricted to safe concurrent use, multiple parts of a program could attempt to modify the same data simultaneously. This can lead to unpredictable behavior, data corruption, or crashes, especially in high-performance or multi-threaded Python environments.

Technologies: [pyo3 (crates.io)](https://junglewise.ai/threats/technologies/pyo3). Vendors: [crates.io](https://junglewise.ai/threats/vendors/crates-io).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Medium severity, with a CVSS score of 6.3, published 12 June 2026.

**Which products and versions are affected?** pyo3 (crates.io) < 0.29.0.

**Is there a fix for This vulnerability?** A patch was published on 2026-06-04: Fix merged into main branch Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is This vulnerability attacked?** It is attacked over the network, in a software library.

**Am I affected?** Check whether you run pyo3 (crates.io) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## Technical details

The vulnerability stems from a missing 'Sync' trait bound on the closures passed to PyCFunction::new_closure and PyCFunction::new_closure_bound. While the API enforced 'Send + static', the lack of 'Sync' allows a closure to be invoked concurrently from multiple Python threads without proper synchronization. This is particularly critical in free-threaded Python environments (no GIL) or when using 'Python::detach' in GIL-enabled environments, as it allows interleaved or parallel execution of the closure's logic. An attacker or a specific execution flow could trigger a data race, leading to undefined behavior or memory corruption. The issue is resolved in PyO3 version 0.29.0 by adding the necessary 'Sync' bound.

## Affected products

- PyO3 pyo3 >= 0.15.0, < 0.29.0

## Timeline

- 2026-06-02: other: Vulnerability discovered and pull request created
- 2026-06-04: patched: Fix merged into main branch
- 2026-06-11: disclosed: Vulnerability disclosed in RustSec and PyO3 0.29.0 release notes
- 2026-06-12: advisory: GitHub Advisory published

## References

- [https://github.com/PyO3/pyo3/pull/6096](https://github.com/PyO3/pyo3/pull/6096)
- [https://github.com/PyO3/pyo3/releases/tag/v0.29.0](https://github.com/PyO3/pyo3/releases/tag/v0.29.0)
- [https://rustsec.org/advisories/RUSTSEC-2026-0177.html](https://rustsec.org/advisories/RUSTSEC-2026-0177.html)

## Related threats

- [PyO3 out-of-bounds read in list and tuple iterators](https://junglewise.ai/threats/pyo3-out-of-bounds-read-in-list-and-tuple-iterators-31441968)
- [RUSTSEC-2026-0177 - Missing `Sync` bound on `PyCFunction::new_closure` closures](https://junglewise.ai/threats/rustsec-2026-0177-missing-sync-bound-on-pycfunction-new-closure-e8081edc)
- [RUSTSEC-2026-0176 - Out-of-bounds read in `nth` / `nth_back` for `PyList` and `PyTuple` iterators](https://junglewise.ai/threats/rustsec-2026-0176-out-of-bounds-read-in-nth-nth-back-for-pylist-and-f3042ce7)
- [PyO3 has type confusion when accessing data from sublasses of subclasses of native types with `abi3` feature](https://junglewise.ai/threats/pyo3-has-type-confusion-when-accessing-data-from-sublasses-of-2db99dde)
- [RUSTSEC-2026-0013 - Type confusion when accessing data from sublasses of subclasses of native types with `abi3`…](https://junglewise.ai/threats/rustsec-2026-0013-type-confusion-when-accessing-data-from-sublasses-of-d320236a)
