gsk: Add a few assertions
authorMatthias Clasen <mclasen@redhat.com>
Fri, 5 May 2023 13:42:34 +0000 (09:42 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 5 May 2023 16:05:10 +0000 (12:05 -0400)
Make sure we don't overflow our fixed-size arrays.

gsk/gl/gskglattachmentstate.c
gsk/gl/gskglcommandqueue.c

index f3f62cb21048c26cca305b35ff6c822a3058f84d..92fe871a3aadac78c75f4790a583f5f7b5cb0b12 100644 (file)
@@ -78,6 +78,7 @@ gsk_gl_attachment_state_bind_texture (GskGLAttachmentState *self,
             target == GL_TEXTURE_2D ||
             target == GL_TEXTURE_3D);
   g_assert (texture >= GL_TEXTURE0 && texture <= GL_TEXTURE16);
+  g_assert (texture - GL_TEXTURE0 < G_N_ELEMENTS (self->textures));
 
   attach = &self->textures[texture - GL_TEXTURE0];
 
index 774b957785b0d27d178f613cd61db62185b2daca..50c9c3908cd2dfa4015ce48542dc6f526e1e139f 100644 (file)
@@ -1161,6 +1161,8 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
           if G_UNLIKELY (batch->draw.bind_count > 0)
             {
               const GskGLCommandBind *bind = &self->batch_binds.items[batch->draw.bind_offset];
+
+              g_assert (bind->texture < G_N_ELEMENTS (textures));
               for (guint i = 0; i < batch->draw.bind_count; i++)
                 {
                   if (textures[bind->texture] != bind->id)