util/printf: be robust against truncated buffers

this can happen with shader aborts. don't blow up with theatrics.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32564>
This commit is contained in:
Alyssa Rosenzweig
2024-12-06 10:50:21 -05:00
committed by Marge Bot
parent 69a0962c70
commit 85e06f5a55
+4
View File
@@ -144,6 +144,10 @@ u_printf_impl(FILE *out, const char *buffer, size_t buffer_size,
for (size_t buf_pos = 0; buf_pos < buffer_size;) {
uint32_t fmt_idx = *(uint32_t*)&buffer[buf_pos];
/* Don't die on invalid printf buffers due to aborted shaders. */
if (fmt_idx == 0)
break;
/* the idx is 1 based */
assert(fmt_idx > 0);
fmt_idx -= 1;