Bug 785734 - WebGL: test for illegal texture sizes for given mipmap level - r=jgilbert, a=akeybl
authorBenoit Jacob <bjacob@mozilla.com>
Sat, 03 Nov 2012 09:35:48 -0400
changeset 82071 331ec7c812f024a60b172fbcc2ddcca824ba9eba
parent 82070 b8f271c4612c4858c88a42647ffa17b141281cc4
child 82072 a04c49a2a2388332ead1850681683eb09b4c7a35
push id325
push userryanvm@gmail.com
push dateSat, 03 Nov 2012 13:37:49 +0000
reviewersjgilbert, akeybl
bugs785734
milestone10.0.11esrpre
Bug 785734 - WebGL: test for illegal texture sizes for given mipmap level - r=jgilbert, a=akeybl
content/canvas/src/WebGLContextGL.cpp
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -955,16 +955,21 @@ WebGLContext::CopyTexImage2D(WebGLenum t
 
     if (level < 0)
         return ErrorInvalidValue("copyTexImage2D: level may not be negative");
 
     WebGLsizei maxTextureSize = MaxTextureSizeForTarget(target);
     if (!(maxTextureSize >> level))
         return ErrorInvalidValue("copyTexImage2D: 2^level exceeds maximum texture size");
 
+    WebGLsizei maxTextureSizeForThisLevel = maxTextureSize >> level;
+
+    if (width > maxTextureSizeForThisLevel || height > maxTextureSizeForThisLevel)
+        return ErrorInvalidValue("copyTexImage2D: width or height exceeds maximum texture size for this level");
+
     if (level >= 1) {
         if (!(is_pot_assuming_nonnegative(width) &&
               is_pot_assuming_nonnegative(height)))
             return ErrorInvalidValue("copyTexImage2D: with level > 0, width and height must be powers of two");
     }
 
     bool texFormatRequiresAlpha = internalformat == LOCAL_GL_RGBA ||
                                     internalformat == LOCAL_GL_ALPHA ||
@@ -4877,18 +4882,20 @@ WebGLContext::TexImage2D_base(WebGLenum 
         return ErrorInvalidValue("texImage2D: level must be >= 0");
 
     if (!(maxTextureSize >> level))
         return ErrorInvalidValue("texImage2D: 2^level exceeds maximum texture size");
 
     if (width < 0 || height < 0)
         return ErrorInvalidValue("texImage2D: width and height must be >= 0");
 
-    if (width > maxTextureSize || height > maxTextureSize)
-        return ErrorInvalidValue("texImage2D: width or height exceeds maximum texture size");
+    WebGLsizei maxTextureSizeForThisLevel = maxTextureSize >> level;
+
+    if (width > maxTextureSizeForThisLevel || height > maxTextureSizeForThisLevel)
+        return ErrorInvalidValue("texImage2D: width or height exceeds maximum texture size for this level");
 
     if (level >= 1) {
         if (!(is_pot_assuming_nonnegative(width) &&
               is_pot_assuming_nonnegative(height)))
             return ErrorInvalidValue("texImage2D: with level > 0, width and height must be powers of two");
     }
 
     if (border != 0)