<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt">New piglit test:<div><a href="http://lists.freedesktop.org/archives/piglit/2012-November/003690.html">http://lists.freedesktop.org/archives/piglit/2012-November/003690.html</a><br>
<br><div class="gmail_quote">On Mon, Nov 5, 2012 at 12:04 PM, Frank Henigman <span dir="ltr"><<a href="mailto:fjhenigman@google.com" target="_blank">fjhenigman@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="font-family:arial,helvetica,sans-serif;font-size:10pt">Should have mentioned it does pass piglit, but now that I look I don't see any tests generating an out-of-bounds array index. I also made my own test program which does go out of bounds, and I'll submit that for inclusion in piglit.<div>
<div class="h5"><br>
<br><div class="gmail_quote">On Fri, Nov 2, 2012 at 4:51 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On 11/02/2012 01:12 PM, Frank Henigman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
validate_uniform_parameters now checks that the array index is<br>
valid. This means if an index is out of bounds, glGetUniform* now<br>
fails with GL_INVALID_OPERATION, as it should.<br>
_mesa_uniform and _mesa_uniform_matrix also call<br>
validate_uniform_parameters so the bounds checks there became<br>
redundant and were removed.<br>
<br>
The test in glGetUniformLocation is modified to check array bounds<br>
so it now returns GL_INVALID_INDEX (-1) if you ask for the location<br>
of a non-existent array element, as it should.<br>
</blockquote>
<br></div>
Do we have piglit tests for either of these cases?<br>
<br>
Do all of the existing piglit tests that pass still pass with this change? It seems like they should...<div><div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
src/mesa/main/uniform_query.<u></u>cpp | 26 +++++++++++++-------------<br>
1 files changed, 13 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/src/mesa/main/uniform_query.<u></u>cpp b/src/mesa/main/uniform_query.<u></u>cpp<br>
index bddb8f9..66a2399 100644<br>
--- a/src/mesa/main/uniform_query.<u></u>cpp<br>
+++ b/src/mesa/main/uniform_query.<u></u>cpp<br>
@@ -237,11 +237,14 @@ validate_uniform_parameters(<u></u>struct gl_context *ctx,<br>
return false;<br>
}<br>
<br>
- /* This case should be impossible. The implication is that a call like<br>
- * glGetUniformLocation(prog, "foo[8]") was successful but "foo" is not an<br>
- * array.<br>
+ /* If the uniform is an array, check that array_index is in bounds.<br>
+ * If not an array, check that array_index is zero.<br>
+ * array_index is unsigned so no need to check for less than zero.<br>
*/<br>
- if (*array_index != 0 && shProg->UniformStorage[*loc].<u></u>array_elements == 0) {<br>
+ unsigned limit = shProg->UniformStorage[*loc].<u></u>array_elements;<br>
+ if (limit == 0)<br>
+ limit = 1;<br>
+ if (*array_index >= limit) {<br>
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",<br>
caller, location);<br>
return false;<br>
@@ -728,9 +731,6 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,<br>
* will have already generated an error.<br>
*/<br>
if (uni->array_elements != 0) {<br>
- if (offset >= uni->array_elements)<br>
- return;<br>
-<br>
count = MIN2(count, (int) (uni->array_elements - offset));<br>
}<br>
<br>
@@ -885,9 +885,6 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,<br>
* will have already generated an error.<br>
*/<br>
if (uni->array_elements != 0) {<br>
- if (offset >= uni->array_elements)<br>
- return;<br>
-<br>
count = MIN2(count, (int) (uni->array_elements - offset));<br>
}<br>
<br>
@@ -1021,10 +1018,13 @@ _mesa_get_uniform_location(<u></u>struct gl_context *ctx,<br>
if (!found)<br>
return GL_INVALID_INDEX;<br>
<br>
- /* Since array_elements is 0 for non-arrays, this causes look-ups of 'a[0]'<br>
- * to (correctly) fail if 'a' is not an array.<br>
+ /* If the uniform is an array, fail if the index is out of bounds.<br>
+ * (A negative index is caught above.) This also fails if the uniform<br>
+ * is not an array, but the user is trying to index it, because<br>
+ * array_elements is zero and offset >= 0.<br>
*/<br>
- if (array_lookup && shProg->UniformStorage[<u></u>location].array_elements == 0) {<br>
+ if (array_lookup<br>
+ && offset >= shProg->UniformStorage[<u></u>location].array_elements) {<br>
return GL_INVALID_INDEX;<br>
}<br>
<br>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br>
</div></div></div>
</blockquote></div><br></div></div>