Mesa (main): mesa: check target/format for Tex(ture)StorageMem*

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Nov 20 02:28:47 UTC 2021


Module: Mesa
Branch: main
Commit: d814539c2b67ca28009dd1b239f444ea086e3b39
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d814539c2b67ca28009dd1b239f444ea086e3b39

Author: Ilia Mirkin <imirkin at alum.mit.edu>
Date:   Thu Nov 11 21:47:15 2021 -0500

mesa: check target/format for Tex(ture)StorageMem*

Noticed while doing an audit around _mesa_get_current_tex usage.

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
Acked-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13767>

---

 src/mesa/main/externalobjects.c | 31 +++++++++++++++++++++++++++++++
 src/mesa/main/texstorage.c      | 11 ++++++-----
 src/mesa/main/texstorage.h      |  4 ++++
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 01c859f8301..972f1279e63 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -25,6 +25,7 @@
 #include "mtypes.h"
 #include "bufferobj.h"
 #include "context.h"
+#include "enums.h"
 #include "externalobjects.h"
 #include "teximage.h"
 #include "texobj.h"
@@ -302,6 +303,21 @@ texstorage_memory(GLuint dims, GLenum target, GLsizei levels,
       return;
    }
 
+   if (!_mesa_is_legal_tex_storage_target(ctx, dims, target)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "%s(illegal target=%s)",
+                  func, _mesa_enum_to_string(target));
+      return;
+   }
+
+   /* Check the format to make sure it is sized. */
+   if (!_mesa_is_legal_tex_storage_format(ctx, internalFormat)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "%s(internalformat = %s)", func,
+                  _mesa_enum_to_string(internalFormat));
+      return;
+   }
+
    texObj = _mesa_get_current_tex_object(ctx, target);
    if (!texObj)
       return;
@@ -363,10 +379,25 @@ texturestorage_memory(GLuint dims, GLuint texture, GLsizei levels,
       return;
    }
 
+   /* Check the format to make sure it is sized. */
+   if (!_mesa_is_legal_tex_storage_format(ctx, internalFormat)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "%s(internalformat = %s)", func,
+                  _mesa_enum_to_string(internalFormat));
+      return;
+   }
+
    texObj = _mesa_lookup_texture(ctx, texture);
    if (!texObj)
       return;
 
+   if (!_mesa_is_legal_tex_storage_target(ctx, dims, texObj->Target)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "%s(illegal target=%s)", func,
+                  _mesa_enum_to_string(texObj->Target));
+      return;
+   }
+
    memObj = lookup_memory_object_err(ctx, memory, func);
    if (!memObj)
       return;
diff --git a/src/mesa/main/texstorage.c b/src/mesa/main/texstorage.c
index 932308c6471..77abc6c511f 100644
--- a/src/mesa/main/texstorage.c
+++ b/src/mesa/main/texstorage.c
@@ -48,11 +48,12 @@
  * This is a bit different than legal_teximage_target() when it comes
  * to cube maps.
  */
-static bool
-legal_texobj_target(const struct gl_context *ctx, GLuint dims, GLenum target)
+bool
+_mesa_is_legal_tex_storage_target(const struct gl_context *ctx,
+                                  GLuint dims, GLenum target)
 {
    if (dims < 1 || dims > 3) {
-      _mesa_problem(ctx, "invalid dims=%u in legal_texobj_target()", dims);
+      _mesa_problem(ctx, "invalid dims=%u in _mesa_is_legal_tex_storage_target()", dims);
       return false;
    }
 
@@ -530,7 +531,7 @@ texstorage_error(GLuint dims, GLenum target, GLsizei levels,
    /* Check target.  This is done here so that texture_storage
     * can receive unsized formats.
     */
-   if (!legal_texobj_target(ctx, dims, target)) {
+   if (!_mesa_is_legal_tex_storage_target(ctx, dims, target)) {
       _mesa_error(ctx, GL_INVALID_ENUM,
                   "%s(illegal target=%s)",
                   caller, _mesa_enum_to_string(target));
@@ -605,7 +606,7 @@ texturestorage_error(GLuint dims, GLuint texture, GLsizei levels,
    /* Check target.  This is done here so that texture_storage
     * can receive unsized formats.
     */
-   if (!legal_texobj_target(ctx, dims, texObj->Target)) {
+   if (!_mesa_is_legal_tex_storage_target(ctx, dims, texObj->Target)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "%s(illegal target=%s)", caller,
                   _mesa_enum_to_string(texObj->Target));
diff --git a/src/mesa/main/texstorage.h b/src/mesa/main/texstorage.h
index f184dfd86eb..74abf1797f6 100644
--- a/src/mesa/main/texstorage.h
+++ b/src/mesa/main/texstorage.h
@@ -131,6 +131,10 @@ extern GLboolean
 _mesa_is_legal_tex_storage_format(const struct gl_context *ctx,
                                   GLenum internalformat);
 
+extern bool
+_mesa_is_legal_tex_storage_target(const struct gl_context *ctx,
+                                  GLuint dims, GLenum target);
+
 extern GLboolean
 _mesa_AllocTextureStorage_sw(struct gl_context *ctx,
                              struct gl_texture_object *texObj,



More information about the mesa-commit mailing list