Mesa (master): trace: Correct transfer box size calculation.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Tue Jul 25 16:18:34 UTC 2017


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

Author: Jose Fonseca <jfonseca at vmware.com>
Date:   Mon Jul 24 14:20:03 2017 +0100

trace: Correct transfer box size calculation.

For textures we must not approximate the calculation with `stride *
height`, or `slice_stride * depth`, as that can easily lead to buffer
overflows, particularly for partial transfers.

This should address the issue that Bruce Cherniak found and diagnosed.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>

---

 src/gallium/drivers/trace/tr_dump.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c
index 78c72492dc..2003222cc1 100644
--- a/src/gallium/drivers/trace/tr_dump.c
+++ b/src/gallium/drivers/trace/tr_dump.c
@@ -448,23 +448,22 @@ void trace_dump_box_bytes(const void *data,
 			  unsigned stride,
 			  unsigned slice_stride)
 {
+   enum pipe_format format = resource->format;
    size_t size;
 
+   assert(box->height > 0);
+   assert(box->depth > 0);
+
+   size =  util_format_get_nblocksx(format, box->width )      * util_format_get_blocksize(format)
+        + (util_format_get_nblocksy(format, box->height) - 1) * stride
+        +                                  (box->depth   - 1) * slice_stride;
+
    /*
     * Only dump buffer transfers to avoid huge files.
     * TODO: Make this run-time configurable
     */
    if (resource->target != PIPE_BUFFER) {
       size = 0;
-   } else {
-      enum pipe_format format = resource->format;
-      if (slice_stride)
-         size = box->depth * slice_stride;
-      else if (stride)
-         size = util_format_get_nblocksy(format, box->height) * stride;
-      else {
-         size = util_format_get_nblocksx(format, box->width) * util_format_get_blocksize(format);
-      }
    }
 
    trace_dump_bytes(data, size);




More information about the mesa-commit mailing list