Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent panic on overflow in validate_push_constants #2232

Merged
merged 1 commit into from
Jun 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions vulkano/src/command_buffer/commands/bind_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,17 @@ where
offset: u32,
_push_constants: &Pc,
) -> Result<(), BindPushError> {
let size = size_of::<Pc>() as u32;
let mut remaining_size = size_of::<Pc>();

if offset % 4 != 0 {
return Err(BindPushError::PushConstantsOffsetNotAligned);
}

if size % 4 != 0 {
if remaining_size % 4 != 0 {
return Err(BindPushError::PushConstantsSizeNotAligned);
}

let mut current_offset = offset;
let mut remaining_size = u32::try_from(size).unwrap();
let mut current_offset = offset as usize;

for range in pipeline_layout
.push_constant_ranges_disjoint()
Expand All @@ -669,12 +668,13 @@ where
{
// there is a gap between ranges, but the passed push_constants contains
// some bytes in this gap, exit the loop and report error
if range.offset > current_offset {
if range.offset as usize > current_offset {
break;
}

// push the minimum of the whole remaining data, and the part until the end of this range
let push_size = remaining_size.min(range.offset + range.size - current_offset);
let push_size =
remaining_size.min(range.offset as usize + range.size as usize - current_offset);
current_offset += push_size;
remaining_size -= push_size;

Expand Down Expand Up @@ -1248,7 +1248,7 @@ pub(in super::super) enum BindPushError {

/// The push constants data to be written at an offset is not included in any push constant
/// range of the pipeline layout.
PushConstantsDataOutOfRange { offset: u32 },
PushConstantsDataOutOfRange { offset: usize },

/// The push constants offset is not a multiple of 4.
PushConstantsOffsetNotAligned,
Expand Down