From 4ec7fdcc53ee608eaf82b8b1f5613033ce51ea31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 09:36:20 +0300 Subject: [PATCH] B17: cros-libva image: replace size asserts with unmap+destroy+Err(INVALID_IMAGE) when libva returns an image smaller than display_resolution --- shims/cros-libva/src/image.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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