forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/b17' into simplify/w1a

Browse files at this commit

e6f9eeb6122711ce70aaf1a87a0a1aa8bfecc7d8Ahmet Kaan GümüşParent: fdbc59cf766a41
shims/cros-libva/src/config.rsmodified+3 -3
@@ -74,13 +74,13 @@ impl Config {
7474 // Safe because `self` represents a valid VAConfig. We first query how
7575 // much space is needed by the C API by passing in NULL in the first
7676 // call to `vaQuerySurfaceAttributes`.
77- let attrs_len: std::os::raw::c_uint = 0;
77+ let mut attrs_len: std::os::raw::c_uint = 0;
7878 va_check(unsafe {
7979 bindings::vaQuerySurfaceAttributes(
8080 self.display.handle(),
8181 self.id,
8282 std::ptr::null_mut(),
83- &attrs_len as *const _ as *mut std::os::raw::c_uint,
83+ &mut attrs_len,
8484 )
8585 })?;
8686
@@ -93,7 +93,7 @@ impl Config {
9393 self.display.handle(),
9494 self.id,
9595 attrs.as_mut_ptr(),
96- &attrs_len as *const _ as *mut std::os::raw::c_uint,
96+ &mut attrs_len,
9797 )
9898 })?;
9999
shims/cros-libva/src/display.rsmodified+6 -10
@@ -45,18 +45,14 @@ impl Iterator for DrmDeviceIterator {
4545 type Item = PathBuf;
4646
4747 fn next(&mut self) -> Option<Self::Item> {
48- match self.cur_idx {
49- idx if idx >= DRM_RENDER_NODE_START + DRM_NUM_NODES => None,
50- idx => {
51- let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, idx));
52- if !path.exists() {
53- None
54- } else {
55- self.cur_idx += 1;
56- Some(path)
57- }
48+ while self.cur_idx < DRM_RENDER_NODE_START + DRM_NUM_NODES {
49+ let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, self.cur_idx));
50+ self.cur_idx += 1;
51+ if path.exists() {
52+ return Some(path);
5853 }
5954 }
55+ None
6056 }
6157 }
6258
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
shims/cros-libva/src/surface.rsmodified+1 -3
@@ -364,9 +364,7 @@ impl<D: SurfaceMemoryDescriptor> Surface<D> {
364364 // to create "safe" descriptors outside of this method and thus from made up values,
365365 // violating the safety guarantee that our FDs are legit.
366366
367- let objects = (0..desc.num_objects as usize)
368- // Make sure we don't go out of bounds.
369- .take(4)
367+ let objects = (0..(desc.num_objects as usize).min(4))
370368 .map(|i| desc.objects[i])
371369 .map(|o| {
372370 DrmPrimeSurfaceDescriptorObject {