mesa/main: fix incorrect depth-error
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 22 Nov 2018 10:10:50 +0000 (11:10 +0100)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 26 Nov 2018 11:29:54 +0000 (12:29 +0100)
If glGetTexImage or glGetnTexImage is called with a level that doesn't
exist, we get an error message on this form:

Mesa: User error: GL_INVALID_VALUE in glGetTexImage(depth = 0)

This is clearly nonsensical, because these APIs don't even have a
depth-parameter. The reason is that get_texture_image_dims() return
all-zero dimensions for non-existent texture-images, and we go on to
validate these dimensions as if they were user-input, because
glGetTextureSubImage requires checking.

So let's split this logic in two, so glGetTextureSubImage can have
stricter input-validation. All arguments that are no longer validated
are generated internally by mesa, so there's no use in validating them.

Fixes: 42891dbaa12 "gettextsubimage: verify zoffset and depth are correct"
Signed-off-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
src/mesa/main/texgetimage.c

index 190f53d62fec59e5f0ea7d6c8ad480bd7ceb134a..dabfcd06a5297828cbcce5a0c08aebdabd0bc9e7 100644 (file)
@@ -1255,7 +1255,6 @@ static bool
 getteximage_error_check(struct gl_context *ctx,
                         struct gl_texture_object *texObj,
                         GLenum target, GLint level,
-                        GLint xoffset, GLint yoffset, GLint zoffset,
                         GLsizei width, GLsizei height, GLsizei depth,
                         GLenum format, GLenum type, GLsizei bufSize,
                         GLvoid *pixels, const char *caller)
@@ -1269,6 +1268,49 @@ getteximage_error_check(struct gl_context *ctx,
       return true;
    }
 
+   if (width == 0 || height == 0 || depth == 0) {
+      /* Not an error, but nothing to do.  Return 'true' so that the
+       * caller simply returns.
+       */
+      return true;
+   }
+
+   if (pbo_error_check(ctx, target, width, height, depth,
+                       format, type, bufSize, pixels, caller)) {
+      return true;
+   }
+
+   texImage = select_tex_image(texObj, target, level, 0);
+   if (teximage_error_check(ctx, texImage, format, caller)) {
+      return true;
+   }
+
+   return false;
+}
+
+
+/**
+ * Do error checking for all (non-compressed) get-texture-image functions.
+ * \return true if any error, false if no errors.
+ */
+static bool
+gettexsubimage_error_check(struct gl_context *ctx,
+                           struct gl_texture_object *texObj,
+                           GLenum target, GLint level,
+                           GLint xoffset, GLint yoffset, GLint zoffset,
+                           GLsizei width, GLsizei height, GLsizei depth,
+                           GLenum format, GLenum type, GLsizei bufSize,
+                           GLvoid *pixels, const char *caller)
+{
+   struct gl_texture_image *texImage;
+
+   assert(texObj);
+
+   if (common_error_check(ctx, texObj, target, level, width, height, depth,
+                          format, type, bufSize, pixels, caller)) {
+      return true;
+   }
+
    if (dimensions_error_check(ctx, texObj, target, level,
                               xoffset, yoffset, zoffset,
                               width, height, depth, caller)) {
@@ -1417,7 +1459,7 @@ _mesa_GetnTexImage(GLenum target, GLint level, GLenum format, GLenum type,
    get_texture_image_dims(texObj, target, level, &width, &height, &depth);
 
    if (getteximage_error_check(ctx, texObj, target, level,
-                               0, 0, 0, width, height, depth,
+                               width, height, depth,
                                format, type, bufSize, pixels, caller)) {
       return;
    }
@@ -1448,7 +1490,7 @@ _mesa_GetTexImage(GLenum target, GLint level, GLenum format, GLenum type,
    get_texture_image_dims(texObj, target, level, &width, &height, &depth);
 
    if (getteximage_error_check(ctx, texObj, target, level,
-                               0, 0, 0, width, height, depth,
+                               width, height, depth,
                                format, type, INT_MAX, pixels, caller)) {
       return;
    }
@@ -1482,7 +1524,7 @@ _mesa_GetTextureImage(GLuint texture, GLint level, GLenum format, GLenum type,
                           &width, &height, &depth);
 
    if (getteximage_error_check(ctx, texObj, texObj->Target, level,
-                               0, 0, 0, width, height, depth,
+                               width, height, depth,
                                format, type, bufSize, pixels, caller)) {
       return;
    }
@@ -1515,9 +1557,10 @@ _mesa_GetTextureSubImage(GLuint texture, GLint level,
       return;
    }
 
-   if (getteximage_error_check(ctx, texObj, texObj->Target, level,
-                               xoffset, yoffset, zoffset, width, height, depth,
-                               format, type, bufSize, pixels, caller)) {
+   if (gettexsubimage_error_check(ctx, texObj, texObj->Target, level,
+                                  xoffset, yoffset, zoffset,
+                                  width, height, depth,
+                                  format, type, bufSize, pixels, caller)) {
       return;
    }