diff --git a/shims/cros-libva/src/config.rs b/shims/cros-libva/src/config.rs index 77550620..777b3a30 100644 --- a/shims/cros-libva/src/config.rs +++ b/shims/cros-libva/src/config.rs @@ -74,13 +74,13 @@ impl Config { // Safe because `self` represents a valid VAConfig. We first query how // much space is needed by the C API by passing in NULL in the first // call to `vaQuerySurfaceAttributes`. - let attrs_len: std::os::raw::c_uint = 0; + let mut attrs_len: std::os::raw::c_uint = 0; va_check(unsafe { bindings::vaQuerySurfaceAttributes( self.display.handle(), self.id, std::ptr::null_mut(), - &attrs_len as *const _ as *mut std::os::raw::c_uint, + &mut attrs_len, ) })?; @@ -93,7 +93,7 @@ impl Config { self.display.handle(), self.id, attrs.as_mut_ptr(), - &attrs_len as *const _ as *mut std::os::raw::c_uint, + &mut attrs_len, ) })?; diff --git a/shims/cros-libva/src/display.rs b/shims/cros-libva/src/display.rs index ef9eef6b..95378bed 100644 --- a/shims/cros-libva/src/display.rs +++ b/shims/cros-libva/src/display.rs @@ -45,18 +45,14 @@ impl Iterator for DrmDeviceIterator { type Item = PathBuf; fn next(&mut self) -> Option { - match self.cur_idx { - idx if idx >= DRM_RENDER_NODE_START + DRM_NUM_NODES => None, - idx => { - let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, idx)); - if !path.exists() { - None - } else { - self.cur_idx += 1; - Some(path) - } + while self.cur_idx < DRM_RENDER_NODE_START + DRM_NUM_NODES { + let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, self.cur_idx)); + self.cur_idx += 1; + if path.exists() { + return Some(path); } } + None } } diff --git a/shims/cros-libva/src/image.rs b/shims/cros-libva/src/image.rs index 2df503ba..536979dc 100644 --- a/shims/cros-libva/src/image.rs +++ b/shims/cros-libva/src/image.rs @@ -57,10 +57,17 @@ impl<'a> Image<'a> { bindings::vaMapBuffer(surface.display().handle(), image.buf, &mut addr) }) { Ok(_) => { - // Assert that libva provided us with a coded resolution that is - // at least as large as `display_resolution`. - assert!(u32::from(image.width) >= display_resolution.0); - assert!(u32::from(image.height) >= display_resolution.1); + if u32::from(image.width) < display_resolution.0 + || u32::from(image.height) < display_resolution.1 + { + // Safe because the buffer was mapped above and `image` is a valid `VAImage`. + unsafe { + bindings::vaUnmapBuffer(surface.display().handle(), image.buf); + bindings::vaDestroyImage(surface.display().handle(), image.image_id); + } + + return Err(va_check(bindings::VA_STATUS_ERROR_INVALID_IMAGE as _).unwrap_err()); + } // Safe since `addr` points to data mapped onto our address space since we called // `vaMapBuffer` above, which also guarantees that the data is valid for diff --git a/shims/cros-libva/src/surface.rs b/shims/cros-libva/src/surface.rs index 35974091..fa200201 100644 --- a/shims/cros-libva/src/surface.rs +++ b/shims/cros-libva/src/surface.rs @@ -364,9 +364,7 @@ impl Surface { // to create "safe" descriptors outside of this method and thus from made up values, // violating the safety guarantee that our FDs are legit. - let objects = (0..desc.num_objects as usize) - // Make sure we don't go out of bounds. - .take(4) + let objects = (0..(desc.num_objects as usize).min(4)) .map(|i| desc.objects[i]) .map(|o| { DrmPrimeSurfaceDescriptorObject {