[Mesa-dev] [PATCH] glsl: Fix overflow of ImageAccess[] array.

Kenneth Graunke kenneth at whitecape.org
Sun Feb 14 01:41:17 UTC 2016


On Saturday, February 13, 2016 8:30:51 PM PST Ilia Mirkin wrote:
> On Sat, Feb 13, 2016 at 8:27 PM, Kenneth Graunke <kenneth at whitecape.org> 
wrote:
> > The ImageAccess array is statically sized to MAX_IMAGE_UNIFORMS:
> >
> >    GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
> >
> > There was no bounds checking ensuring we don't overflow.  Passing in a
> > shader with too many uniforms would cause writes to extend into other
> > fields, such as sh->NumImages.
> >
> > Later linker checks already handle reporting an error when there are too
> > many images, so just avoid corrupting structures here.
> >
> > This rearranges the logic a bit to look more like the sampler case.
> >
> > Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> > ---
> >  src/compiler/glsl/link_uniforms.cpp | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/
link_uniforms.cpp
> > index 7072c16..f08ca47 100644
> > --- a/src/compiler/glsl/link_uniforms.cpp
> > +++ b/src/compiler/glsl/link_uniforms.cpp
> > @@ -649,15 +649,15 @@ private:
> >               current_var->data.image_write_only ? GL_WRITE_ONLY :
> >                  GL_READ_WRITE);
> >
> > -         for (unsigned j = 0; j < MAX2(1, uniform->array_elements); ++j)
> > -            prog->_LinkedShaders[shader_type]->
> > -               ImageAccess[this->next_image + j] = access;
> > +         const unsigned first = this->next_image;
> >
> >           /* Increment the image index by 1 for non-arrays and by the
> >            * number of array elements for arrays.
> >            */
> >           this->next_image += MAX2(1, uniform->array_elements);
> >
> > +         for (unsigned i = first; i < MIN2(next_image, 
MAX_IMAGE_UNIFORMS); i++)
> 
> It's a bit odd that you do this->next_image += foo, but then use
> next_image directly... if that's the style, I guess it's OK.

Yeah.  We're not terribly consistent.  One developer preferred this->
always, while others preferred not using it, so it ended up being a
"use it if you want" style.

Here I would have kept this-> except that I hate linewrapping for loop
conditions...

> 
> > +            prog->_LinkedShaders[shader_type]-> ImageAccess[i] = access;
> 
> Remove the space before ImageAccess?

Good catch.

> 
> With that,
> 
> Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
> 
> >        }
> >     }
> >
> > --
> > 2.7.1
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160213/615de88c/attachment.sig>


More information about the mesa-dev mailing list