glsl/images: bounds check image unit assignment
authorDave Airlie <airlied@redhat.com>
Mon, 23 May 2016 02:49:25 +0000 (12:49 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 31 May 2016 00:41:44 +0000 (10:41 +1000)
The CTS test:
GL45-CTS.multi_bind.dispatch_bind_image_textures
binds 192 image uniforms, we reject this later,
but not until after we trash the contents of the
struct gl_shader.

Error now reads:
Too many compute shader image uniforms (192 > 16)
instead of
Too many compute shader image uniforms (2745344416 > 16)

Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: "12.0" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/compiler/glsl/link_uniform_initializers.cpp

index c6346d573ab7ac8ea44cb8fd9a2e0474dd78aa84..bf6d394ea8909bf0820d9fe875d8e4f93a616b20 100644 (file)
@@ -145,6 +145,8 @@ set_opaque_binding(void *mem_ctx, gl_shader_program *prog,
                     storage->opaque[sh].active) {
                for (unsigned i = 0; i < elements; i++) {
                   const unsigned index = storage->opaque[sh].index + i;
+                  if (index >= ARRAY_SIZE(shader->ImageUnits))
+                     break;
                   shader->ImageUnits[index] = storage->storage[i].i;
                }
             }