From 070aaa1c9f4d98b24d787d3420fc9ac358210d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 6 Jul 2025 09:07:31 -0400 Subject: [PATCH] nir/lower_io: validate that location and num_slots fit in the bitfields Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_lower_io.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 10b17096371..16c5cb8e258 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -320,9 +320,16 @@ emit_load(struct lower_io_state *state, nir_intrinsic_set_dest_type(load, dest_type); if (load->intrinsic != nir_intrinsic_load_uniform) { + int location = var->data.location; + unsigned num_slots = get_number_of_slots(state, var); + + /* Maximum values in nir_io_semantics. */ + assert(location >= 0 && location <= 127); + assert(num_slots <= 63); + nir_io_semantics semantics = { 0 }; - semantics.location = var->data.location; - semantics.num_slots = get_number_of_slots(state, var); + semantics.location = location; + semantics.num_slots = num_slots; semantics.fb_fetch_output = var->data.fb_fetch_output; if (semantics.fb_fetch_output) { semantics.fb_fetch_output_coherent = @@ -478,9 +485,16 @@ emit_store(struct lower_io_state *state, nir_def *data, } } + int location = var->data.location; + unsigned num_slots = get_number_of_slots(state, var); + + /* Maximum values in nir_io_semantics. */ + assert(location >= 0 && location <= 127); + assert(num_slots <= 63); + nir_io_semantics semantics = { 0 }; - semantics.location = var->data.location; - semantics.num_slots = get_number_of_slots(state, var); + semantics.location = location; + semantics.num_slots = num_slots; semantics.dual_source_blend_index = var->data.index; semantics.gs_streams = gs_streams; semantics.medium_precision = is_medium_precision(b->shader, var);