summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kurtz <djkurtz@chromium.org>2014-02-16 17:44:14 +0800
committerIan Romanick <ian.d.romanick@intel.com>2014-02-17 10:57:05 -0800
commit4f9d98dbaea90c11a930fd774382ff364892ce3f (patch)
treee6f1abec426a7c9a845c11cf12b9f5e7902139d8
parentec5077087a6a3c751740958c1a1ae8ae14a12b62 (diff)
texturing/s3tc-errors: double check GL_TEXTURE parameters and alloc
If the GL does not actually support one of the compression formats in s3tc_formats, it may silently choose a different actual internalformat. In such a case, the resulting compressed image size may be larger, leading to memory corruption when the bigger-than-expected image is read back with glGetCompressedTexImage() into a buffer that was allocated to the expected, smaller, size. Instead, first confirm the texture has really been compressed, that the format is as expected, and that the size matches our pre-computed expected size. If any of these fail, set pass to false and spit an error, but keep going, using the actual format and size returned by the GL. Ian Romanick pointed out that "if we're going to all this effort, we should probably go all the way. A follow-on patch should check that glGetCompressedTexImage doesn't over-run the buffer." v2: * Fixed parameter check block format per Ian Romanick review * Updated commit message title per Brian Paul review * Function call continuation lines align with open '(' (like in rest of file). Signed-off-by: Daniel Kurtz <djkurtz@chromium.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
-rw-r--r--tests/texturing/s3tc-errors.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/tests/texturing/s3tc-errors.c b/tests/texturing/s3tc-errors.c
index 710625ce0..19a871b7e 100644
--- a/tests/texturing/s3tc-errors.c
+++ b/tests/texturing/s3tc-errors.c
@@ -125,14 +125,17 @@ check_gl_error2_(GLenum err1, GLenum err2, int line)
static bool
-test_format(int width, int height, GLfloat *image, GLenum format)
+test_format(int width, int height, GLfloat *image, GLenum requested_format)
{
- GLubyte *compressed_image =
- malloc(piglit_compressed_image_size(format, width, height));
+ GLubyte *compressed_image;
GLenum format2;
int x, y, w, h;
GLuint tex;
bool pass = true;
+ GLuint expected_size;
+ bool is_compressed;
+ GLuint compressed_size;
+ GLenum format;
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
@@ -143,12 +146,47 @@ test_format(int width, int height, GLfloat *image, GLenum format)
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0,
+ glTexImage2D(GL_TEXTURE_2D, 0, requested_format, width, height, 0,
GL_RGBA, GL_FLOAT, image);
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
pass = check_rendering(width, height) && pass;
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED,
+ &is_compressed);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT,
+ &format);
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
+ GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
+ &compressed_size);
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ if (!is_compressed) {
+ printf("Image was not compressed\n");
+ pass = false;
+ }
+
+ if (format != requested_format) {
+ printf("Internal Format mismatch. Found: 0x%04x Expected: 0x%04x\n",
+ format, requested_format);
+ pass = false;
+ }
+
+ expected_size = piglit_compressed_image_size(requested_format, width,
+ height);
+
+ if (compressed_size != expected_size) {
+ printf("Compressed image size mismatch. Found: %u Expected: %u\n",
+ compressed_size, expected_size);
+ pass = false;
+ }
+
+ /* Use GL_TEXTURE_COMPRESSED_IMAGE_SIZE even if it wasn't what we
+ * expected to avoid corruption due to under-allocated buffer.
+ */
+ compressed_image = malloc(compressed_size);
+
/* Read back the compressed image data */
glGetCompressedTexImage(GL_TEXTURE_2D, 0, compressed_image);