summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorentin Noël <corentin.noel@collabora.com>2023-06-07 19:34:59 +0200
committerMarge Bot <emma+marge@anholt.net>2023-06-09 09:50:52 +0000
commite5790d03d3eec349b150c67d5a5557d47a18c62a (patch)
tree85ecf22f77e72aac83719ea394657b02effb114b
parentc234d6cb4ecbe201a521a78a042bc437f799c74f (diff)
shader: Do some basic sanity checks in emit_ios and return early on failure
Allows to just reject the shader in case the provided shader is corrupted. Signed-off-by: Corentin Noël <corentin.noel@collabora.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1143>
-rw-r--r--src/vrend_shader.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index e5ce7e9..938168d 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -6902,11 +6902,23 @@ emit_ios_generic_outputs(const struct dump_ctx *ctx,
&ctx->key->fs_info, ctx->key->flatshade);
if (ctx->outputs[i].name == TGSI_SEMANTIC_COLOR) {
+ if (ctx->outputs[i].sid >= 64) {
+ vrend_printf("Number of output id exceeded, max is 64\n");
+ set_buf_error(glsl_strbufs);
+ return;
+ }
+
front_back_color_emitted_flags[ctx->outputs[i].sid] |= FRONT_COLOR_EMITTED;
fc_emitted |= 1ull << ctx->outputs[i].sid;
}
if (ctx->outputs[i].name == TGSI_SEMANTIC_BCOLOR) {
+ if (ctx->outputs[i].sid >= 64) {
+ vrend_printf("Number of output id exceeded, max is 64\n");
+ set_buf_error(glsl_strbufs);
+ return;
+ }
+
front_back_color_emitted_flags[ctx->outputs[i].sid] |= BACK_COLOR_EMITTED;
bc_emitted |= 1ull << ctx->outputs[i].sid;
}
@@ -6987,6 +6999,8 @@ static void emit_ios_vs(const struct dump_ctx *ctx,
emit_ios_generic_outputs(ctx, glsl_strbufs, generic_ios, texcoord_ios,
front_back_color_emitted_flags, force_color_two_side,
can_emit_generic_default);
+ if (strbuf_get_error(&glsl_strbufs->glsl_main))
+ return;
if (ctx->key->color_two_side || ctx->force_color_two_side) {
bool fcolor_emitted, bcolor_emitted;
@@ -7340,6 +7354,8 @@ static void emit_ios_geom(const struct dump_ctx *ctx,
emit_ios_generic_outputs(ctx, glsl_strbufs, generic_ios, texcoord_ios,
front_back_color_emitted_flags, force_color_two_side,
can_emit_generic_geom);
+ if (strbuf_get_error(&glsl_strbufs->glsl_main))
+ return;
emit_ios_per_vertex_in(ctx, glsl_strbufs, has_pervertex);
@@ -7463,6 +7479,8 @@ static void emit_ios_tes(const struct dump_ctx *ctx,
emit_ios_generic_outputs(ctx, glsl_strbufs, generic_ios, texcoord_ios,
front_back_color_emitted_flags, force_color_two_side,
can_emit_generic_default);
+ if (strbuf_get_error(&glsl_strbufs->glsl_main))
+ return;
emit_ios_per_vertex_in(ctx, glsl_strbufs, has_pervertex);
emit_ios_per_vertex_out(ctx, glsl_strbufs, "");
@@ -7575,6 +7593,9 @@ static int emit_ios(const struct dump_ctx *ctx,
return glsl_ver_required;
}
+ if (strbuf_get_error(&glsl_strbufs->glsl_main))
+ return glsl_ver_required;
+
const struct sematic_info generic = {TGSI_SEMANTIC_GENERIC, 'g'};
const struct sematic_info texcoord = {TGSI_SEMANTIC_TEXCOORD, 't'};