From 03df494ea4749b55fc7458db91542cee2d85ccc4 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 12 Jul 2022 16:44:41 -0700 Subject: [PATCH] mesa: Mark render-to-texture as unsafe if there's no pipe_resource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's be slightly more defensive here. If a texture image doesn't have an associated pipe_resource allocated, then render_texture() will pass that along to _mesa_update_renderbuffer_surface(), which will crash on a NULL pointer dereference. So, if there isn't a pipe_resource, then we should just skip this altogteher. Today, this isn't an issue, because each gl_texture_image always allocates a pipe_resource up front. On a branch of mine, I prototyped some improvements to the compressed texture fallback handling, where it would defer resource allocation, examine the source image's block data, and dynamically select a format based on that, then allocate it later. With that prototype in place, we saw crashes the Android "My Talking Tom" series of games, which appear to be attaching ASTC textures to a framebuffer color attachment. That FBO would be incomplete anyway, as ASTC textures aren't renderable, but we got into a situation where the render-to-texture code was crashing due to the lack of pt before it could properly signal that it was incomplete and bailing. Technically, we don't need this now, but I figure that being defensive won't hurt and this would probably save whoever encounters such an issue in the future a bunch of frustrating debugging. Reviewed-by: Marek Olšák Reviewed-by: Jordan Justen Part-of: --- src/mesa/main/fbobject.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index ba9dcd37d37..5127d9634c0 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -512,6 +512,7 @@ driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment *att) att->Texture->Image[att->CubeMapFace][att->TextureLevel]; if (!texImage || + !texImage->pt || texImage->Width == 0 || texImage->Height == 0 || texImage->Depth == 0) return false;