public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/python-safetensors] rawhide: Update PyO3 to 0.29; fixes RUSTSEC-2026-0176, RUSTSEC-2026-0177
@ 2026-07-08  5:58 Benjamin A. Beasley
  0 siblings, 0 replies; only message in thread
From: Benjamin A. Beasley @ 2026-07-08  5:58 UTC (permalink / raw)
  To: git-commits

A new commit has been pushed.

Repo   : rpms/python-safetensors
Branch : rawhide
Commit : d46dfcf6288f8baf61a103f447e0b5e2de56eb3a
Author : Benjamin A. Beasley <code@musicinmybrain.net>
Date   : 2026-07-08T06:40:36+01:00
Stats  : +115/-0 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/python-safetensors/c/d46dfcf6288f8baf61a103f447e0b5e2de56eb3a?branch=rawhide

Log:
Update PyO3 to 0.29; fixes RUSTSEC-2026-0176, RUSTSEC-2026-0177

---
diff --git a/python-safetensors.spec b/python-safetensors.spec
index a5a4ba8..70d2d1a 100644
--- a/python-safetensors.spec
+++ b/python-safetensors.spec
@@ -26,6 +26,13 @@ SourceLicense:  Apache-2.0
 URL:            https://github.com/huggingface/safetensors
 Source:         %{url}/archive/refs/tags/v%{version}/safetensors-%{version}.tar.gz
 
+# feat: bump pyo3 to 0.29 (#796)
+# https://github.com/safetensors/safetensors/commit/b3d8d72f341daa219b7a6c7e9e7335f5a14348a4
+# Without changes to .github/workflows/python.yml or to
+# bindings/python/Cargo.lock, which are not relevant here and are more likely
+# to produce conflicts.
+Patch:          safetensors-0.8.0-pyo3-0.29.patch
+
 BuildRequires:  python3-devel
 BuildRequires:  cargo-rpm-macros >= 24
 BuildRequires:  rust2rpm-helper

diff --git a/safetensors-0.8.0-pyo3-0.29.patch b/safetensors-0.8.0-pyo3-0.29.patch
new file mode 100644
index 0000000..fc120d2
--- /dev/null
+++ b/safetensors-0.8.0-pyo3-0.29.patch
@@ -0,0 +1,108 @@
+diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml
+index a79d4928b..6ac166589 100644
+--- a/bindings/python/Cargo.toml
++++ b/bindings/python/Cargo.toml
+@@ -10,7 +10,7 @@ name = "safetensors_rust"
+ crate-type = ["cdylib"]
+ 
+ [dependencies]
+-pyo3 = { version = "0.28", features = ["abi3", "abi3-py310"] }
++pyo3 = { version = "0.29", features = ["abi3", "abi3-py310"] }
+ memmap2 = "0.9"
+ serde_json = "1.0"
+ 
+diff --git a/bindings/python/src/dlpack.rs b/bindings/python/src/dlpack.rs
+index b8e18027f..ecf35932c 100644
+--- a/bindings/python/src/dlpack.rs
++++ b/bindings/python/src/dlpack.rs
+@@ -1,8 +1,10 @@
+ //! DLPack v0 producer + Python capsule wrapping.
+ 
+-use std::ffi::{c_char, c_void};
++use std::ffi::{c_void, CStr};
++use std::ptr::NonNull;
+ 
+ use pyo3::prelude::*;
++use pyo3::types::PyCapsule;
+ 
+ use safetensors::Dtype;
+ 
+@@ -70,7 +72,7 @@ pub struct DLManagedTensor {
+     pub deleter: Option<unsafe extern "C" fn(*mut DLManagedTensor)>,
+ }
+ 
+-const CAPSULE_NAME: &[u8] = b"dltensor\0";
++const CAPSULE_NAME: &CStr = c"dltensor";
+ 
+ /// Source of the `data` pointer [`to_capsule`] writes into the `DLTensor`.
+ ///
+@@ -221,7 +223,7 @@ pub(crate) fn to_capsule<B: AsDevicePtr>(
+     shape: Vec<i64>,
+     dtype: DLDataType,
+     device: DLDevice,
+-) -> PyResult<Py<PyAny>> {
++) -> PyResult<Py<PyCapsule>> {
+     let ndim = shape.len() as i32;
+     let data = device_buf.as_device_ptr();
+ 
+@@ -251,21 +253,28 @@ pub(crate) fn to_capsule<B: AsDevicePtr>(
+         deleter: Some(managed_tensor_deleter::<B>),
+     }));
+ 
+-    let name_ptr = CAPSULE_NAME.as_ptr() as *const c_char;
+-    // SAFETY: for all the following unsafe calls, all data was produced by this function and is valid each the call.
+-    // In case of failure, we clean up the managed tensor ourselves to avoid leaks, since the capsule destructor won't run.
+-    let capsule_ptr = unsafe {
+-        pyo3::ffi::PyCapsule_New(managed as *mut c_void, name_ptr, Some(capsule_destructor))
++    // `managed` came from `Box::into_raw`, so it is non-null.
++    let managed_ptr = NonNull::new(managed as *mut c_void).unwrap();
++    // SAFETY: `managed_ptr` points to a live `DLManagedTensor` produced above, and
++    // `capsule_destructor` reclaims it via the registered deleter.
++    let capsule = unsafe {
++        PyCapsule::new_with_pointer_and_destructor(
++            py,
++            managed_ptr,
++            CAPSULE_NAME,
++            Some(capsule_destructor),
++        )
+     };
+-    if capsule_ptr.is_null() {
++    // On failure the destructor was never registered, so reclaim the tensor ourselves.
++    let capsule = capsule.map_err(|e| {
+         unsafe { managed_tensor_deleter::<B>(managed) };
+-        return Err(PyErr::fetch(py));
+-    }
+-    Ok(unsafe { Bound::from_owned_ptr(py, capsule_ptr) }.unbind())
++        e
++    })?;
++    Ok(capsule.unbind())
+ }
+ 
+ unsafe extern "C" fn capsule_destructor(capsule: *mut pyo3::ffi::PyObject) {
+-    let name_ptr = CAPSULE_NAME.as_ptr() as *const c_char;
++    let name_ptr = CAPSULE_NAME.as_ptr();
+     if unsafe { pyo3::ffi::PyCapsule_IsValid(capsule, name_ptr) } == 0 {
+         return;
+     }
+diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs
+index 6b94a0283..fe5cda085 100644
+--- a/bindings/python/src/lib.rs
++++ b/bindings/python/src/lib.rs
+@@ -11,6 +11,8 @@ use pyo3::exceptions::{PyException, PyFileNotFoundError};
+ use pyo3::prelude::*;
+ use pyo3::sync::OnceLockExt;
+ use pyo3::types::IntoPyDict;
++#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
++use pyo3::types::PyCapsule;
+ use pyo3::types::{PyBool, PyByteArray, PyBytes, PyDict, PyEllipsis, PyList, PySlice, PyTuple};
+ use pyo3::Bound as PyBound;
+ use pyo3::{intern, PyErr};
+@@ -2132,7 +2134,7 @@ fn torch_supports_mps_dlpack() -> bool {
+ fn ingest_dlpack_mps(
+     py: Python<'_>,
+     framework: &Framework,
+-    capsule: Py<PyAny>,
++    capsule: Py<PyCapsule>,
+ ) -> PyResult<Py<PyAny>> {
+     match framework {
+         Framework::Pytorch => {

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-08  5:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-08  5:58 [rpms/python-safetensors] rawhide: Update PyO3 to 0.29; fixes RUSTSEC-2026-0176, RUSTSEC-2026-0177 Benjamin A. Beasley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox