forge
Explore
Log in

Don't you dare go Hollow

B17: cros-libva image: replace size asserts with unmap+destroy+Err(INVALID_IMAGE) when libva returns an image smaller than display_resolution

Browse files at this commit

4ec7fdcc53ee608eaf82b8b1f5613033ce51ea31Ahmet Kaan GümüşParent: bc8bcf2
shims/cros-libva/src/image.rsmodified+11 -4
@@ -57,10 +57,17 @@ impl<'a> Image<'a> {
5757 bindings::vaMapBuffer(surface.display().handle(), image.buf, &mut addr)
5858 }) {
5959 Ok(_) => {
60- // Assert that libva provided us with a coded resolution that is
61- // at least as large as `display_resolution`.
62- assert!(u32::from(image.width) >= display_resolution.0);
63- assert!(u32::from(image.height) >= display_resolution.1);
60+ if u32::from(image.width) < display_resolution.0
61+ || u32::from(image.height) < display_resolution.1
62+ {
63+ // Safe because the buffer was mapped above and `image` is a valid `VAImage`.
64+ unsafe {
65+ bindings::vaUnmapBuffer(surface.display().handle(), image.buf);
66+ bindings::vaDestroyImage(surface.display().handle(), image.image_id);
67+ }
68+
69+ return Err(va_check(bindings::VA_STATUS_ERROR_INVALID_IMAGE as _).unwrap_err());
70+ }
6471
6572 // Safe since `addr` points to data mapped onto our address space since we called
6673 // `vaMapBuffer` above, which also guarantees that the data is valid for