<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 15, 2018 at 7:42 AM, Daniel Stone <span dir="ltr"><<a href="mailto:daniels@collabora.com" target="_blank">daniels@collabora.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The previous commit reworked the checks intel_from_planar() to check the<br>
right individual cases for regular/planar/aux buffers, and do size<br>
checks in all cases.<br>
<br>
Unfortunately, the aux size check was broken, and required the aux<br>
surface to be allocated with the correct aux stride, but full image<br>
height (!).<br>
<br>
As the ISL aux surface is not recorded in the DRIimage, we cannot easily<br>
access it to check. Instead, store the aux size from when we do have the<br>
ISL surface to hand, and check against that later when we go to access<br>
the aux surface.<br>
<br>
Signed-off-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
Fixes: c2c4e5bae3ba ("i965: Fix bugs in intel_from_planar")<br>
Cc: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
---<br>
 src/mesa/drivers/dri/i965/<wbr>intel_image.h  |  3 +++<br>
 src/mesa/drivers/dri/i965/<wbr>intel_screen.c | 10 +++++++---<br>
 2 files changed, 10 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_image.h b/src/mesa/drivers/dri/i965/<wbr>intel_image.h<br>
index 78d689a11a3..a8193c6def9 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_image.h<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_image.h<br>
@@ -98,6 +98,9 @@ struct __DRIimageRec {<br>
    /** Pitch of the auxiliary compression surface. */<br>
    uint32_t aux_pitch;<br>
<br>
+   /** Total size in bytes of the auxiliary compression surface. */<br>
+   uint32_t aux_size;<br>
+<br>
    /**<br>
     * Provided by EGL_EXT_image_dma_buf_import.<br>
     * \{<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
index 1c0fffa2e96..a21b08e51b1 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
@@ -750,6 +750,7 @@ intel_create_image_common(__<wbr>DRIscreen *dri_screen,<br>
    if (aux_surf.size) {<br>
       image->aux_offset = surf.size;<br>
       image->aux_pitch = aux_surf.row_pitch;<br>
+      image->aux_size = aux_surf.size;<br></blockquote><div><br></div><div>We also need to do this in create_image_from_fds_common<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    }<br>
<br>
    return image;<br>
@@ -1312,7 +1313,7 @@ intel_query_dma_buf_modifiers(<wbr>__DRIscreen *_screen, int fourcc, int max,<br>
 static __DRIimage *<br>
 intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)<br>
 {<br>
-    int width, height, offset, stride, dri_format;<br>
+    int width, height, offset, stride, size, dri_format;<br>
     __DRIimage *image;<br>
<br>
     if (parent == NULL)<br>
@@ -1331,24 +1332,27 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)<br>
        int index = f->planes[plane].buffer_index;<br>
        offset = parent->offsets[index];<br>
        stride = parent->strides[index];<br>
+       size = height * stride;<br>
     } else if (plane == 0) {<br>
        /* The only plane of a non-planar image: copy the parent definition<br>
         * directly. */<br>
        dri_format = parent->dri_format;<br>
        offset = parent->offset;<br>
        stride = parent->pitch;<br>
+       size = height * stride;<br>
     } else if (plane == 1 && parent->modifier != DRM_FORMAT_MOD_INVALID &&<br>
                isl_drm_modifier_has_aux(<wbr>parent->modifier)) {<br>
        /* Auxiliary plane */<br>
        dri_format = parent->dri_format;<br>
        offset = parent->aux_offset;<br>
        stride = parent->aux_pitch;<br>
+       size = parent->aux_size;<br>
     } else {<br>
        return NULL;<br>
     }<br>
<br>
-    if (offset + height * stride > parent->bo->size) {<br>
-       _mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds");<br>
+    if (offset + size > parent->bo->size) {<br>
+       _mesa_warning(NULL, "intel_from_planar: subimage out of bounds");<br>
        return NULL;<br>
     }<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.14.3<br>
<br>
</font></span></blockquote></div><br></div></div>