From fc7e0ef0fbc73c198204b58078e9f54e4aa8003e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 6 Mar 2015 21:24:42 +0100 Subject: [PATCH] shader: add a check for number of imm and ubo I think UBO limit is 32, but IMM is not, so we better had some checks to avoid overflow --- src/vrend_shader.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 77ae0a6..884bf77 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -24,6 +24,7 @@ #include "tgsi/tgsi_info.h" #include "tgsi/tgsi_iterate.h" +#include "util/u_memory.h" #include #include #include @@ -531,6 +532,10 @@ iter_declaration(struct tgsi_iterate_context *iter, break; case TGSI_FILE_CONSTANT: if (decl->Declaration.Dimension) { + if (ctx->num_ubo >= ARRAY_SIZE(ctx->ubo_idx)) { + fprintf(stderr, "Number of uniforms exceeded, max is %lu\n", ARRAY_SIZE(ctx->ubo_idx)); + return FALSE; + } ctx->ubo_idx[ctx->num_ubo] = decl->Dim.Index2D; ctx->ubo_sizes[ctx->num_ubo] = decl->Range.Last + 1; ctx->num_ubo++; @@ -616,8 +621,11 @@ iter_immediate( int i; int first = ctx->num_imm; - if (first > MAX_IMMEDIATE) - return FALSE; + if (first >= ARRAY_SIZE(ctx->imm)) { + fprintf(stderr, "Number of immediates exceeded, max is: %lu\n", ARRAY_SIZE(ctx->imm)); + return FALSE; + } + ctx->imm[first].type = imm->Immediate.DataType; for (i = 0; i < 4; i++) { if (imm->Immediate.DataType == TGSI_IMM_FLOAT32) {