From d1a9314c28ddc946acbb2ac7907a909b84a0531a Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:50:54 +0200 Subject: [PATCH] Fix UB in `impl VertexBufferCollection for Vec>` (#2577) --- 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 b5354b66..442af664 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) } } }