Skip to content

Commit ce02c19

Browse files
fix #5 possible ptr overflow in VMABuffer::set_data
1 parent 72ad576 commit ce02c19

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,34 @@ unsafe impl Sync for Error {}
99
pub enum Error {
1010
#[error("corresponding function loader was not loaded: {0}")]
1111
FnLoaderNotInitialized(String),
12+
1213
#[error("called function which requires a head on headless instance")]
1314
HeadCallOnHeadlessInstance,
15+
1416
#[error("no suitable GPU was found to create the physical device")]
1517
NoSuitableGPUFound,
18+
1619
#[error("device extension was requested but is not supported: {0}")]
1720
RequiredDeviceExtensionNotSupported(String),
21+
1822
#[error("requested surface format is not supported by the surface")]
1923
RequestedSurfaceFormatNotSupported,
24+
2025
#[error("more frames in flight were requested than the surface supports")]
2126
InsufficientFramesInFlightSupported,
27+
2228
#[error("requested present mode is not supported by the surface")]
2329
PresentModeNotSupported,
2430

2531
#[error("the requested image layout transition is not supported from: {0:?} to: {1:?}")]
2632
UnsupportedImageLayoutTransition(ImageLayout, ImageLayout),
33+
2734
#[error("tried to set data on an unmapped buffer")]
2835
WriteAttemptToUnmappedBuffer,
2936

37+
#[error("tried to write past the length of mapped buffer. Buffer allocation size: {0:?} bytes. Write offset: {1:?} bytes. Write length: {2:?} bytes")]
38+
WriteAttemptOverflow(usize, usize, usize),
39+
3040
#[error("the file extension of the shader could not be handled")]
3141
UnknownShaderFileExtension,
3242

src/vma_buffer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ impl VMABuffer {
179179
return Err(Error::WriteAttemptToUnmappedBuffer);
180180
};
181181

182+
if offset + data.len() > self.allocation.size() as usize / size_of::<T>(){
183+
return Err(Error::WriteAttemptOverflow(self.allocation.size() as usize, offset, data.len() * size_of::<T>()));
184+
}
185+
182186
let mut ptr = ptr.as_ptr() as *mut T;
183187
unsafe {
184188
ptr = ptr.add(offset);

0 commit comments

Comments
 (0)