From dfb0adcce3cb5378ed08feeb95b3efec5537de63 Mon Sep 17 00:00:00 2001 From: LegionMammal978 Date: Mon, 3 Apr 2023 11:39:21 -0400 Subject: [PATCH] fix(ffi): add `repr(transparent)` to `hyper_context` (#3191) The default representation does not guarantee the absence of initial padding, which is necessary for the transmute to be sound. Signed-off-by: Sven Pfennig --- src/ffi/task.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ffi/task.rs b/src/ffi/task.rs index ef54fe408f..e40bb29c5f 100644 --- a/src/ffi/task.rs +++ b/src/ffi/task.rs @@ -66,6 +66,7 @@ struct TaskFuture { } /// An async context for a task that contains the related waker. +#[repr(transparent)] pub struct hyper_context<'a>(Context<'a>); /// A waker that is saved and used to waken a pending task. @@ -378,7 +379,7 @@ where impl hyper_context<'_> { pub(crate) fn wrap<'a, 'b>(cx: &'a mut Context<'b>) -> &'a mut hyper_context<'b> { - // A struct with only one field has the same layout as that field. + // A repr(transparent) struct with only one field has the same layout as that field. unsafe { std::mem::transmute::<&mut Context<'_>, &mut hyper_context<'_>>(cx) } } }