rusticl/spirv: protect against 0 length in slice::from_raw_parts
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11584 Cc: mesa-stable Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30410>
This commit is contained in:
@@ -224,8 +224,10 @@ impl SPIRVBin {
|
||||
|
||||
fn kernel_infos(&self) -> &[clc_kernel_info] {
|
||||
match self.info {
|
||||
None => &[],
|
||||
Some(info) => unsafe { slice::from_raw_parts(info.kernels, info.num_kernels as usize) },
|
||||
Some(info) if info.num_kernels > 0 => unsafe {
|
||||
slice::from_raw_parts(info.kernels, info.num_kernels as usize)
|
||||
},
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,6 +409,10 @@ impl SPIRVBin {
|
||||
|
||||
pub fn spec_constant(&self, spec_id: u32) -> Option<clc_spec_constant_type> {
|
||||
let info = self.info?;
|
||||
if info.num_spec_constants == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let spec_constants =
|
||||
unsafe { slice::from_raw_parts(info.spec_constants, info.num_spec_constants as usize) };
|
||||
|
||||
|
Reference in New Issue
Block a user