Bug 1315866 - Always-too-large level during tex image specification is INVALID_VALUE. - r=ethlin
authorJeff Gilbert <jdashg@gmail.com>
Wed, 14 Dec 2016 19:03:25 -0800
changeset 450689 013060399bd78eab379e3a4c07b3a4a55ad7aea8
parent 450688 9555007ca062942383043b00d266de2fabbc66f2
child 450690 58701d19071dfb9974f6828753817695971bab84
push id38944
push userbmo:leftysolara@gmail.com
push dateSun, 18 Dec 2016 16:01:15 +0000
reviewersethlin
bugs1315866
milestone53.0a1
Bug 1315866 - Always-too-large level during tex image specification is INVALID_VALUE. - r=ethlin MozReview-Commit-ID: 9fBznguuq1l
dom/canvas/WebGLTextureUpload.cpp
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -470,29 +470,30 @@ ValidateTexImage(WebGLContext* webgl, We
 
     *out_imageInfo = &imageInfo;
     return true;
 }
 
 // For *TexImage*
 bool
 WebGLTexture::ValidateTexImageSpecification(const char* funcName, TexImageTarget target,
-                                            GLint level, uint32_t width, uint32_t height,
-                                            uint32_t depth,
+                                            GLint rawLevel, uint32_t width,
+                                            uint32_t height, uint32_t depth,
                                             WebGLTexture::ImageInfo** const out_imageInfo)
 {
     if (mImmutable) {
         mContext->ErrorInvalidOperation("%s: Specified texture is immutable.", funcName);
         return false;
     }
 
     // Do this early to validate `level`.
     WebGLTexture::ImageInfo* imageInfo;
-    if (!ValidateTexImage(mContext, this, funcName, target, level, &imageInfo))
+    if (!ValidateTexImage(mContext, this, funcName, target, rawLevel, &imageInfo))
         return false;
+    const uint32_t level(rawLevel);
 
     if (mTarget == LOCAL_GL_TEXTURE_CUBE_MAP &&
         width != height)
     {
         mContext->ErrorInvalidValue("%s: Cube map images must be square.", funcName);
         return false;
     }
 
@@ -507,43 +508,54 @@ WebGLTexture::ValidateTexImageSpecificat
      * lower nor higher than MAX_TEXTURE_SIZE.
      *
      * Note that mImplMaxTextureSize must be >= than the advertized MAX_TEXTURE_SIZE.
      * For simplicity, we advertize MAX_TEXTURE_SIZE as mImplMaxTextureSize.
      */
 
     uint32_t maxWidthHeight = 0;
     uint32_t maxDepth = 0;
+    uint32_t maxLevel = 0;
 
     MOZ_ASSERT(level <= 31);
     switch (target.get()) {
     case LOCAL_GL_TEXTURE_2D:
         maxWidthHeight = mContext->mImplMaxTextureSize >> level;
         maxDepth = 1;
+        maxLevel = CeilingLog2(mContext->mImplMaxTextureSize);
         break;
 
     case LOCAL_GL_TEXTURE_3D:
         maxWidthHeight = mContext->mImplMax3DTextureSize >> level;
         maxDepth = maxWidthHeight;
+        maxLevel = CeilingLog2(mContext->mImplMax3DTextureSize);
         break;
 
     case LOCAL_GL_TEXTURE_2D_ARRAY:
         maxWidthHeight = mContext->mImplMaxTextureSize >> level;
         // "The maximum number of layers for two-dimensional array textures (depth)
         //  must be at least MAX_ARRAY_TEXTURE_LAYERS for all levels."
         maxDepth = mContext->mImplMaxArrayTextureLayers;
+        maxLevel = CeilingLog2(mContext->mImplMaxTextureSize);
         break;
 
     default: // cube maps
         MOZ_ASSERT(IsCubeMap());
         maxWidthHeight = mContext->mImplMaxCubeMapTextureSize >> level;
         maxDepth = 1;
+        maxLevel = CeilingLog2(mContext->mImplMaxCubeMapTextureSize);
         break;
     }
 
+    if (level > maxLevel) {
+        mContext->ErrorInvalidValue("%s: Requested level is not supported for target.",
+                                    funcName);
+        return false;
+    }
+
     if (width > maxWidthHeight ||
         height > maxWidthHeight ||
         depth > maxDepth)
     {
         mContext->ErrorInvalidValue("%s: Requested size at this level is unsupported.",
                                     funcName);
         return false;
     }