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

Author: Danylo Piliaiev <[email protected]>
Date:   Fri Aug 21 16:35:28 2020 +0300

nir/large_constants: Eliminate out-of-bounds writes to large constants

Out-of-bounds writes could be eliminated per spec:

Section 5.11 (Out-of-Bounds Accesses) of the GLSL 4.60 spec says:

"In the subsections described above for array, vector, matrix and
 structure accesses, any out-of-bounds access produced undefined
 behavior.... Out-of-bounds writes may be discarded or overwrite
 other variables of the active program."

Fixes: 1235850522cd5e7b07701f7065996430ca1514b6
Signed-off-by: Danylo Piliaiev <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6428>

---

 src/compiler/nir/nir_opt_large_constants.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir_opt_large_constants.c 
b/src/compiler/nir/nir_opt_large_constants.c
index fec6cceb325..b1d90be8336 100644
--- a/src/compiler/nir/nir_opt_large_constants.c
+++ b/src/compiler/nir/nir_opt_large_constants.c
@@ -118,8 +118,11 @@ handle_constant_store(void *mem_ctx, struct var_info *info,
       info->constant_data = rzalloc_size(mem_ctx, var_size);
    }
 
-   char *dst = (char *)info->constant_data +
-               nir_deref_instr_get_const_offset(deref, size_align);
+   const unsigned offset = nir_deref_instr_get_const_offset(deref, size_align);
+   if (offset >= info->constant_data_size)
+      return;
+
+   char *dst = (char *)info->constant_data + offset;
 
    for (unsigned i = 0; i < num_components; i++) {
       if (!(writemask & (1 << i)))

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to