[Mesa-dev] [PATCH 1/2] intel: Prevent huge lastlevel values from being computed.

Stéphane Marchesin marcheu at chromium.org
Tue Sep 4 12:15:55 PDT 2012


The current computation for the lastlevel is based on the level size and can
lead to writing past the end of the texture array. Instead we clamp it by
MAX_TEXTURE_LEVELS.
---
 src/mesa/drivers/dri/intel/intel_tex_image.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index fe9040c..7ef258b 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -88,6 +88,11 @@ intel_miptree_create_for_teximage(struct intel_context *intel,
 	 lastLevel = firstLevel;
       } else {
 	 lastLevel = firstLevel + _mesa_logbase2(MAX2(MAX2(width, height), depth));
+	 /* We tried to guess the last level based on the texture size, make
+	  * sure we don't go past MAX_TEXTURE_LEVELS since it's hardcoded
+	  * in many places.
+	  */
+	 lastLevel = MIN2(lastLevel, MAX_TEXTURE_LEVELS - 1);
       }
    }
 
-- 
1.7.5.3.367.ga9930



More information about the mesa-dev mailing list