From dfff5927842c95492f097b85e722ed7129642845 Mon Sep 17 00:00:00 2001 From: edef Date: Thu, 17 Oct 2024 22:37:05 +0000 Subject: [PATCH] fix(users/edef/weave): use safer_owning_ref owning_ref has serious unsoundness. Change-Id: Ie760697cd6399e6bc75f1ad17c9bb74adc077a35 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12656 Reviewed-by: edef Tested-by: BuildkiteCI Autosubmit: edef Reviewed-by: flokli --- users/edef/weave/Cargo.lock | 20 ++++++++--------- users/edef/weave/Cargo.nix | 42 ++++++++++++++++++----------------- users/edef/weave/Cargo.toml | 2 +- users/edef/weave/src/bytes.rs | 4 ++-- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/users/edef/weave/Cargo.lock b/users/edef/weave/Cargo.lock index de53d26d9..aaa77014f 100644 --- a/users/edef/weave/Cargo.lock +++ b/users/edef/weave/Cargo.lock @@ -1021,15 +1021,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "owning_ref" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" -dependencies = [ - "stable_deref_trait", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -1586,6 +1577,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "safer_owning_ref" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af21b9de2df966f61c07b5b541c81c98225b86e48ababd43366a642654de30ef" +dependencies = [ + "stable_deref_trait", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -2036,9 +2036,9 @@ dependencies = [ "anyhow", "hashbrown 0.14.5", "nix-compat", - "owning_ref", "polars", "rayon", + "safer_owning_ref", "tokio", ] diff --git a/users/edef/weave/Cargo.nix b/users/edef/weave/Cargo.nix index 2a6851c7c..a06bae091 100644 --- a/users/edef/weave/Cargo.nix +++ b/users/edef/weave/Cargo.nix @@ -3004,22 +3004,6 @@ rec { }; resolvedDefaultFeatures = [ "alloc" "default" "race" "std" ]; }; - "owning_ref" = rec { - crateName = "owning_ref"; - version = "0.4.1"; - edition = "2015"; - sha256 = "1kjj9m28wjv452jw49p1mp3d8ql058x78v4bz00avr7rvsnmpxbg"; - authors = [ - "Marvin Löbel " - ]; - dependencies = [ - { - name = "stable_deref_trait"; - packageId = "stable_deref_trait"; - } - ]; - - }; "parking_lot" = rec { crateName = "parking_lot"; version = "0.12.3"; @@ -5499,6 +5483,24 @@ rec { "no-panic" = [ "dep:no-panic" ]; }; }; + "safer_owning_ref" = rec { + crateName = "safer_owning_ref"; + version = "0.5.0"; + edition = "2015"; + sha256 = "1vrhvra2cr3a6r1vvflawj35n8lq3k443ddm0wfgcrpr5pgbj8dg"; + libName = "owning_ref"; + authors = [ + "Marvin Löbel " + "Noam Ta Shma noam.tashma@gmail.com" + ]; + dependencies = [ + { + name = "stable_deref_trait"; + packageId = "stable_deref_trait"; + } + ]; + + }; "scopeguard" = rec { crateName = "scopeguard"; version = "1.2.0"; @@ -6784,10 +6786,6 @@ rec { name = "nix-compat"; packageId = "nix-compat"; } - { - name = "owning_ref"; - packageId = "owning_ref"; - } { name = "polars"; packageId = "polars"; @@ -6797,6 +6795,10 @@ rec { name = "rayon"; packageId = "rayon"; } + { + name = "safer_owning_ref"; + packageId = "safer_owning_ref"; + } { name = "tokio"; packageId = "tokio"; diff --git a/users/edef/weave/Cargo.toml b/users/edef/weave/Cargo.toml index 2058f6d36..69cf3cf7e 100644 --- a/users/edef/weave/Cargo.toml +++ b/users/edef/weave/Cargo.toml @@ -11,7 +11,7 @@ members = ["."] anyhow = { version = "1.0.79", features = ["backtrace"] } hashbrown = "0.14.3" nix-compat = { version = "0.1.0", path = "../../../tvix/nix-compat" } -owning_ref = "0.4.1" +safer_owning_ref = "0.5.0" rayon = "1.8.1" tokio = { version = "1.36.0", features = ["full"] } diff --git a/users/edef/weave/src/bytes.rs b/users/edef/weave/src/bytes.rs index c6dc2ebb4..689b8fdfc 100644 --- a/users/edef/weave/src/bytes.rs +++ b/users/edef/weave/src/bytes.rs @@ -3,7 +3,7 @@ use polars::export::arrow::buffer::Buffer; use std::ops::Deref; /// An shared `[[u8; N]]` backed by a Polars [Buffer]. -pub type FixedBytes = OwningRef; +pub type FixedBytes = OwningRef<'static, Bytes, [[u8; N]]>; /// Wrapper struct to make [Buffer] implement [StableAddress]. /// TODO(edef): upstream the `impl` @@ -13,7 +13,7 @@ pub struct Bytes(pub Buffer); unsafe impl StableAddress for Bytes {} impl Bytes { - pub fn map(self, f: impl FnOnce(&[u8]) -> &U) -> OwningRef { + pub fn map(self, f: impl FnOnce(&[u8]) -> &U) -> OwningRef<'static, Self, U> { OwningRef::new(self).map(f) } }