texgetimage: Add check for the effective target to GetTextureSubImage
[mesa.git] / src / mesa / main / texgetimage.c
index b9002787344f86d7cc0cb3886f9f00d4cf174c75..b0ced1eac0f87c02f0574b5465fdd3a189618890 100644 (file)
@@ -654,7 +654,7 @@ get_tex_memcpy(struct gl_context *ctx,
 
       if (src) {
          if (bytesPerRow == dstRowStride && bytesPerRow == srcRowStride) {
-            memcpy(dst, src, bytesPerRow * texImage->Height);
+            memcpy(dst, src, bytesPerRow * height);
          }
          else {
             GLuint row;
@@ -1429,6 +1429,11 @@ _mesa_GetTextureImage(GLuint texture, GLint level, GLenum format, GLenum type,
       return;
    }
 
+   if (!legal_getteximage_target(ctx, texObj->Target, true)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller);
+      return;
+   }
+
    get_texture_image_dims(texObj, texObj->Target, level,
                           &width, &height, &depth);
 
@@ -1460,6 +1465,12 @@ _mesa_GetTextureSubImage(GLuint texture, GLint level,
       return;
    }
 
+   if (!legal_getteximage_target(ctx, texObj->Target, true)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "%s(buffer/multisample texture)", caller);
+      return;
+   }
+
    if (getteximage_error_check(ctx, texObj, texObj->Target, level,
                                xoffset, yoffset, zoffset, width, height, depth,
                                format, type, bufSize, pixels, caller)) {