diff --git a/vulkano/src/command_buffer/validity/vertex_buffers.rs b/vulkano/src/command_buffer/validity/vertex_buffers.rs index 9465c5c078..371d4c21bf 100644 --- a/vulkano/src/command_buffer/validity/vertex_buffers.rs +++ b/vulkano/src/command_buffer/validity/vertex_buffers.rs @@ -95,7 +95,10 @@ pub(in super::super) fn check_vertex_buffers( .max_multiview_instance_index .unwrap_or(0); - if first_instance + instance_count > max_instance_index + 1 { + // The condition is somewhat convoluted to avoid integer overflows. + let out_of_range = first_instance > max_instance_index + || (instance_count > 0 && instance_count - 1 > max_instance_index - first_instance); + if out_of_range { return Err(CheckVertexBufferError::TooManyInstances { instance_count, max_instance_count: max_instance_index + 1, // TODO: this can overflow