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