Skip to content

Commit 7ca33d4

Browse files
authored
report memory exposure in PyO3's PyString::from_object (#2266)
1 parent bfc4e6e commit 7ca33d4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

crates/pyo3/RUSTSEC-0000-0000.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```toml
2+
[advisory]
3+
id = "RUSTSEC-0000-0000"
4+
package = "pyo3"
5+
date = "2025-04-01"
6+
url = "https://github.com/PyO3/pyo3/issues/5005"
7+
categories = ["memory-exposure"]
8+
keywords = ["buffer-overflow"]
9+
10+
[affected]
11+
functions = { "pyo3::types::PyString::from_object" = ["< 0.24.1"], "pyo3::types::PyString::from_object_bound" = ["< 0.24.1", ">= 0.21.0"] }
12+
13+
[versions]
14+
patched = [">= 0.24.1"]
15+
```
16+
17+
# Risk of buffer overflow in `PyString::from_object`
18+
19+
`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).
20+
21+
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.

0 commit comments

Comments
 (0)