Mesa (master): draw: do bounds checking of array elements (debug only)

Brian Paul brianp at kemper.freedesktop.org
Thu Jul 29 23:32:08 UTC 2010


Module: Mesa
Branch: master
Commit: b4c8de1ff24d4d5e2fe550da54249934320acab4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b4c8de1ff24d4d5e2fe550da54249934320acab4

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jul 29 17:24:20 2010 -0600

draw: do bounds checking of array elements (debug only)

Make sure that all the element indexes actually lie inside the vertex
buffer.

Also, rename pipe_run() to pipe_run_elts() to be more specific.

And assert/check the vertex count for the non-indexed case.

---

 src/gallium/auxiliary/draw/draw_pipe.c |   35 +++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_pipe.c b/src/gallium/auxiliary/draw/draw_pipe.c
index 8cd75ec..144f10a 100644
--- a/src/gallium/auxiliary/draw/draw_pipe.c
+++ b/src/gallium/auxiliary/draw/draw_pipe.c
@@ -220,7 +220,7 @@ static void do_triangle( struct draw_context *draw,
    do_point( draw,                              \
              verts + stride * (elts[i0] & ~DRAW_PIPE_FLAG_MASK) )
 
-#define FUNC pipe_run
+#define FUNC pipe_run_elts
 #define ARGS                                    \
     struct draw_context *draw,                  \
     unsigned prim,                              \
@@ -269,14 +269,29 @@ void draw_pipeline_run( struct draw_context *draw,
         i < prim_info->primitive_count;
         start += prim_info->primitive_lengths[i], i++)
    {
-      unsigned count = prim_info->primitive_lengths[i];
-
-      pipe_run(draw,
-               prim_info->prim,
-               vert_info->verts,
-               vert_info->stride,
-               prim_info->elts + start,
-               count);
+      const unsigned count = prim_info->primitive_lengths[i];
+
+#if DEBUG
+      /* make sure none of the element indexes go outside the vertex buffer */
+      {
+         unsigned max_index = 0x0, i;
+         /* find the largest element index */
+         for (i = 0; i < count; i++) {
+            unsigned int index = (prim_info->elts[start + i]
+                                  & ~DRAW_PIPE_FLAG_MASK);
+            if (index > max_index)
+               max_index = index;
+         }
+         assert(max_index <= vert_info->count);
+      }
+#endif
+
+      pipe_run_elts(draw,
+                    prim_info->prim,
+                    vert_info->verts,
+                    vert_info->stride,
+                    prim_info->elts + start,
+                    count);
    }
 
    draw->pipeline.verts = NULL;
@@ -378,6 +393,8 @@ void draw_pipeline_run_linear( struct draw_context *draw,
       draw->pipeline.vertex_stride = vert_info->stride;
       draw->pipeline.vertex_count = count;
 
+      assert(count <= vert_info->count);
+
       pipe_run_linear(draw,
                       prim_info->prim,
                       (struct vertex_header*)verts,




More information about the mesa-commit mailing list