Mesa (staging/18.2): egl/dri2: Guard against invalid fourcc formats

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 31 08:52:51 UTC 2018


Module: Mesa
Branch: staging/18.2
Commit: 17ceea55e58200ff7b52ad6dbb209f946dc9a1cd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=17ceea55e58200ff7b52ad6dbb209f946dc9a1cd

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Tue Aug 28 16:43:57 2018 -0500

egl/dri2: Guard against invalid fourcc formats

We already reject attempts to import images with invalid fourcc formats
but don't really guard the queries all that well.  This makes us error
out in any calls to eglQueryDmaBufModifiersEXT if the given format is
not a valid fourcc format.  We also add an assert to ensure that drivers
don't advertise any non-fourcc formats.

Cc: mesa-stable at lists.freedesktop.org
Tested-By: Eero Tamminen <eero.t.tamminen at intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom at intel.com>
(cherry picked from commit 8c1b9882b2e0cde0b1ad9c6844fd5939d3bd4b24)

---

 src/egl/drivers/dri2/egl_dri2.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 84018d8642..da7d8b9cd1 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2353,6 +2353,18 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp,
                                             formats, count))
       return EGL_FALSE;
 
+   if (max > 0) {
+      /* Assert that all of the formats returned are actually fourcc formats.
+       * Some day, if we want the internal interface function to be able to
+       * return the fake fourcc formats defined in dri_interface.h, we'll have
+       * to do something more clever here to pair the list down to just real
+       * fourcc formats so that we don't leak the fake internal ones.
+       */
+      for (int i = 0; i < *count; i++) {
+         assert(dri2_num_fourcc_format_planes(formats[i]) > 0);
+      }
+   }
+
    return EGL_TRUE;
 }
 
@@ -2363,6 +2375,9 @@ dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
 
+   if (dri2_num_fourcc_format_planes(format) == 0)
+      return _eglError(EGL_BAD_PARAMETER, "invalid fourcc format");
+
    if (max < 0)
       return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
 




More information about the mesa-commit mailing list