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 commit4ec7fdcc53ee608eaf82b8b1f5613033ce51ea31Parent: bc8bcf21 changed file +11 -4
shims/cros-libva/src/image.rsmodified+11 -4
| @@ -57,10 +57,17 @@ impl<'a> Image<'a> { | ||
| 57 | 57 | bindings::vaMapBuffer(surface.display().handle(), image.buf, &mut addr) |
| 58 | 58 | }) { |
| 59 | 59 | 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 | + } | |
| 64 | 71 | |
| 65 | 72 | // Safe since `addr` points to data mapped onto our address space since we called |
| 66 | 73 | // `vaMapBuffer` above, which also guarantees that the data is valid for |