HistoryEditJSON (OSV)

RUSTSEC-2024-0378

Risk of use-after-free in borrowed reads from Python weak references

Reported
Issued
Package
pyo3 (crates.io)
Type
Vulnerability
Categories
Keywords
#use-after-free
References
Patched
  • >=0.22.4
Unaffected
  • <0.22.0
Affected Functions
Version
pyo3::types::PyWeakrefMethods::get_object_borrowed
  • <0.22.4, >=0.22.0
pyo3::types::PyWeakrefMethods::upgrade_borrowed
  • <0.22.4, >=0.22.0
pyo3::types::PyWeakrefMethods::upgrade_borrowed_as
  • <0.22.4, >=0.22.0
pyo3::types::PyWeakrefMethods::upgrade_borrowed_as_exact
  • <0.22.4, >=0.22.0
pyo3::types::PyWeakrefMethods::upgrade_borrowed_as_unchecked
  • <0.22.4, >=0.22.0

Description

The family of functions to read "borrowed" values from Python weak references were fundamentally unsound, because the weak reference does itself not have ownership of the value. At any point the last strong reference could be cleared and the borrowed value would become dangling.

In PyO3 0.22.4 these functions have all been deprecated and patched to leak a strong reference as a mitigation. PyO3 0.23 will remove these functions entirely.

Advisory available under CC0-1.0 license.