From f62104efe657ce3c693620cb022c0eeb8b931e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Cortier?= <3809077+CBenoit@users.noreply.github.com> Date: Wed, 26 Mar 2025 01:55:30 +0100 Subject: [PATCH] fix(ffi): use patched diplomat (#723) This patched version of Diplomat is backporting an important fix from the more up to date versions of Diplomat. Without this patch, the code generated by the diplomat::bridge macro contains an easy to trigger UB. This UB is triggered by the generated C# code when passing an empty byte[] array. --- Cargo.lock | 6 ++---- Cargo.toml | 5 +++++ ffi/Cargo.toml | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99bcf48f..47c30254 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1229,8 +1229,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31672b3ebc3c7866c3c98726f7a9a5ac8f13962e77d3c8225f6be49a7b8c5f2" +source = "git+https://github.com/CBenoit/diplomat?rev=6dc806e80162b6b39509a04a2835744236cd2396#6dc806e80162b6b39509a04a2835744236cd2396" dependencies = [ "diplomat_core", "proc-macro2", @@ -1247,8 +1246,7 @@ checksum = "f7b0f23d549a46540e26e5490cd44c64ced0d762959f1ffdec6ab0399634cf3c" [[package]] name = "diplomat_core" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfaa5e13e8b8735d2338f2836c06cd8643902ab87dda1dd07dbb351998ddc127" +source = "git+https://github.com/CBenoit/diplomat?rev=6dc806e80162b6b39509a04a2835744236cd2396#6dc806e80162b6b39509a04a2835744236cd2396" dependencies = [ "lazy_static", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 8f9ddf9f..e0020e93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,3 +143,8 @@ opt-level = 3 [profile.test.package.rand_chacha] opt-level = 3 + +[patch.crates-io] +# FIXME: We need to catch up with Diplomat upstream again, but this is a significant amount of work. +# In the meantime, we use this forked version which fixes an undefined behavior in the code expanded by the bridge macro. +diplomat = { git = "https://github.com/CBenoit/diplomat", rev = "6dc806e80162b6b39509a04a2835744236cd2396" } diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml index 5a7b3932..fbefb2e7 100644 --- a/ffi/Cargo.toml +++ b/ffi/Cargo.toml @@ -27,4 +27,3 @@ embed-resource = "3.0" [lints] workspace = true -