Skip to content

Python::allow_threads is unsound in the presence of send_wrapper. #2141

Open
@mejrs

Description

@mejrs

It allows smuggling Python types into the closure:

use pyo3::prelude::*;
use pyo3::types::PyString;
use send_wrapper::SendWrapper;

fn main() {
    Python::with_gil(|py| {
        let string = PyString::new(py, "foo");

        let wrapped = SendWrapper::new(string);

        py.allow_threads(|| {
            let smuggled: &PyString = *wrapped;
            println!("{:?}", smuggled);
        });
    });
}

Results in
error: process didn't exit successfully: target\debug\my_module.exe (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

So I'm not sure whose fault it is:

  • Ours, for using Send for something it wasn't meant to.
  • send_wrapper's, for assuming others didn't put arbitrary restrictions on Send.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions