From 2504863ece8f963aaba3d4f11f35ea6a8cc06aeb Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:33:24 +0200 Subject: [PATCH] Fix UB in `impl VertexBufferCollection for Vec>` --- vulkano/src/pipeline/graphics/vertex_input/collection.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vulkano/src/pipeline/graphics/vertex_input/collection.rs b/vulkano/src/pipeline/graphics/vertex_input/collection.rs index b5354b6664..442af66455 100644 --- a/vulkano/src/pipeline/graphics/vertex_input/collection.rs +++ b/vulkano/src/pipeline/graphics/vertex_input/collection.rs @@ -1,5 +1,5 @@ use crate::buffer::Subbuffer; -use std::mem; +use std::mem::{self, ManuallyDrop}; /// A collection of vertex buffers. pub trait VertexBuffersCollection { @@ -32,8 +32,13 @@ impl VertexBuffersCollection for Vec> { mem::align_of::>(), ); + let mut this = ManuallyDrop::new(self); + let cap = this.capacity(); + let len = this.len(); + let ptr = this.as_mut_ptr(); + // SAFETY: All `Subbuffer`s share the same layout. - unsafe { mem::transmute::>, Vec>>(self) } + unsafe { Vec::from_raw_parts(ptr.cast(), len, cap) } } }