From 5397854877c1b17f21c16e43365e1c2e353dc8ba Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 16 Jan 2025 10:08:15 +0100 Subject: [PATCH] glamor: reject configs using unsupported rgbBits size The supported color depths is a hardcoded list for now, so we need to honor the value exposed there otherwise we'll get inconsistencies between what glXGetFBConfigs and XListDepths report to applications. Signed-off-by: Pierre-Eric Pelloux-Prayer Part-of: --- glamor/glamor_glx_provider.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/glamor/glamor_glx_provider.c b/glamor/glamor_glx_provider.c index 77ccc3c8b..c27141c7c 100644 --- a/glamor/glamor_glx_provider.c +++ b/glamor/glamor_glx_provider.c @@ -140,12 +140,14 @@ egl_create_glx_drawable(ClientPtr client, __GLXscreen *screen, * - drawable type masks is suspicious */ static struct egl_config * -translate_eglconfig(struct egl_screen *screen, EGLConfig hc, +translate_eglconfig(ScreenPtr pScreen, struct egl_screen *screen, EGLConfig hc, struct egl_config *chain, Bool direct_color, Bool double_buffer, Bool duplicate_for_composite, Bool srgb_only) { EGLint value; + bool valid_depth; + int i; struct egl_config *c = calloc(1, sizeof *c); if (!c) @@ -218,6 +220,19 @@ translate_eglconfig(struct egl_screen *screen, EGLConfig hc, } #undef GET + /* Only expose this config if rgbBits matches a supported + * depth value. + */ + valid_depth = false; + for (i = 0; i < pScreen->numDepths && !valid_depth; i++) { + if (pScreen->allowedDepths[i].depth == c->base.rgbBits) + valid_depth = true; + } + if (!valid_depth) { + free(c); + return chain; + } + /* derived state: config caveats */ eglGetConfigAttrib(screen->display, hc, EGL_CONFIG_CAVEAT, &value); if (value == EGL_NONE) @@ -340,13 +355,13 @@ egl_mirror_configs(ScreenPtr pScreen, struct egl_screen *screen) for (j = 0; j < 3; j++) /* direct_color */ for (k = 0; k < 2; k++) /* double_buffer */ { if (can_srgb) - c = translate_eglconfig(screen, host_configs[i], c, + c = translate_eglconfig(pScreen, screen, host_configs[i], c, /* direct_color */ j == 1, /* double_buffer */ k > 0, /* duplicate_for_composite */ j == 0, /* srgb_only */ true); - c = translate_eglconfig(screen, host_configs[i], c, + c = translate_eglconfig(pScreen, screen, host_configs[i], c, /* direct_color */ j == 1, /* double_buffer */ k > 0, /* duplicate_for_composite */ j == 0,