[Mesa-stable] [PATCH] i965: Fix bugs in intel_from_planar

Jason Ekstrand jason at jlekstrand.net
Sat Feb 10 06:50:01 UTC 2018


This commit fixes two bugs in intel_from_planar.  First, if the planar
format was non-NULL but only had a single plane, we were falling through
to the planar case.  If we had a CCS modifier and plane == 1, we would
return NULL instead of the CCS plane.  Second, if we did end up in the
planar_format == NULL case and the modifier was DRM_FORMAT_MOD_INVALID,
we would end up segfaulting in isl_drm_modifier_has_aux.

Cc: mesa-stable at lists.freedesktop.org
Fixes: 8f6e54c92966bb94a3f05f2cc7ea804273e125ad
---
 src/mesa/drivers/dri/i965/intel_screen.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 1f866cf..d4878f1 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -1313,12 +1313,18 @@ static __DRIimage *
 intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
 {
     int width, height, offset, stride, dri_format, index;
-    const struct intel_image_format *f;
     __DRIimage *image;
 
-    if (parent == NULL) {
+    if (parent == NULL)
        return NULL;
-    } else if (parent->planar_format == NULL) {
+
+    const struct intel_image_format *f = parent->planar_format;
+    const int nplanes = f ? f->nplanes : 1;
+
+    if (plane > nplanes) {
+       if (parent->modifier == DRM_FORMAT_MOD_INVALID)
+          return NULL;
+
        const bool is_aux =
           isl_drm_modifier_has_aux(parent->modifier) && plane == 1;
        if (!is_aux)
@@ -1332,10 +1338,6 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
     } else {
        /* Planar formats don't support aux buffers/images */
        assert(!isl_drm_modifier_has_aux(parent->modifier));
-       f = parent->planar_format;
-
-       if (plane >= f->nplanes)
-          return NULL;
 
        width = parent->width >> f->planes[plane].width_shift;
        height = parent->height >> f->planes[plane].height_shift;
-- 
2.5.0.400.gff86faf



More information about the mesa-stable mailing list