st/glsl_to_tgsi: fix potential crash when allocating temporaries
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 28 Apr 2016 19:09:12 +0000 (21:09 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Sat, 30 Apr 2016 15:41:32 +0000 (17:41 +0200)
When index - t->temps_size is greater than 4096, allocating space for
temporaries on demand will miserably crash. This can happen when a game
uses a lot of temporaries like the recent released Tomb raider.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Cc: "11.1 11.2" <mesa-stable@lists.freedesktop.org>
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 3c4c91b0e2f7835eb0e02597cf4c636e631b0b15..060e854caa123d42de2d73056c2dee765954456f 100644 (file)
@@ -5360,7 +5360,7 @@ dst_register(struct st_translate *t, gl_register_file file, unsigned index,
    case PROGRAM_TEMPORARY:
       /* Allocate space for temporaries on demand. */
       if (index >= t->temps_size) {
-         const int inc = 4096;
+         const int inc = align(index - t->temps_size + 1, 4096);
 
          t->temps = (struct ureg_dst*)
                     realloc(t->temps,