From 247946a5e440496a5c06d764d5d8ed11c2ef8074 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 3 Oct 2023 19:48:29 +0200 Subject: [PATCH] mesa: check numlevels and numlayers when creating a texture view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v2: Compare against zero only, because the values are unsigned and can't be negative (Tapani Pälli) CC: mesa-stable Signed-off-by: Gert Wollny Reviewed-by: Emma Anholt (v1) Reviewed-by: Tapani Pälli Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/textureview.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c index f8850e69944..e682346748d 100644 --- a/src/mesa/main/textureview.c +++ b/src/mesa/main/textureview.c @@ -608,6 +608,22 @@ texture_view(struct gl_context *ctx, struct gl_texture_object *origTexObj, } if (!no_error) { + /* OpenGL 4.6 (Core Profile) - May 14, 2018, 8.18 Texture Views, p.271 + * An INVALID_OPERATION error is generated if the computed values of + * TEXTURE_VIEW_NUM_LEVELS or TEXTURE_VIEW_NUM_LAYERS for texture, + * as described above, are less than or equal to zero. + */ + if (newViewNumLevels == 0) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glTextureView(invalid minlevels or numlevels)"); + return; + } + if (newViewNumLayers == 0) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glTextureView(invalid minlayers or numlayers)"); + return; + } + /* If the dimensions of the original texture are larger than the maximum * supported dimensions of the new target, the error INVALID_OPERATION is * generated. For example, if the original texture has a TEXTURE_2D_ARRAY