OSDN Git Service

Prevent division by 0
authorAlexis Hetu <sugoi@google.com>
Wed, 27 Sep 2017 18:43:38 +0000 (14:43 -0400)
committerAlexis Hétu <sugoi@google.com>
Fri, 29 Sep 2017 21:31:50 +0000 (21:31 +0000)
If imageSize is 0, inputPitch may be 0, which would cause a division
by 0. In any case, if imageSize is 0, there's no work to perform, so
we just skip loadCompressedData() entirely in that case.

Bug:765094

Change-Id: Iedc6516ef6d025d24a8827597045cb3b83599e4a
Reviewed-on: https://swiftshader-review.googlesource.com/12648
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/OpenGL/libGL/Texture.cpp
src/OpenGL/libGLES_CM/Texture.cpp
src/OpenGL/libGLESv2/Texture.cpp

index e0756d2..38b9cc6 100644 (file)
@@ -181,7 +181,7 @@ void Texture::setImage(GLenum format, GLenum type, GLint unpackAlignment, const
 
 void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *image)
 {
-       if(pixels && image)
+       if(pixels && image && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
        {
                image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), 1, imageSize, pixels);
        }
@@ -232,7 +232,7 @@ void Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
                return error(GL_INVALID_OPERATION);
        }
 
-       if(pixels)
+       if(pixels && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
        {
                image->loadCompressedData(xoffset, yoffset, 0, width, height, 1, imageSize, pixels);
        }
index 80a3886..18e9fbf 100644 (file)
@@ -239,7 +239,7 @@ void Texture::setImage(egl::Context *context, GLenum format, GLenum type, GLint
 
 void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, egl::Image *image)
 {
-       if(pixels && image)
+       if(pixels && image && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
        {
                image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), 1, imageSize, pixels);
        }
@@ -292,7 +292,7 @@ void Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
                return error(GL_INVALID_OPERATION);
        }
 
-       if(pixels)
+       if(pixels && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
        {
                image->loadCompressedData(xoffset, yoffset, 0, width, height, 1, imageSize, pixels);
        }
index b0a46a5..0b09e11 100644 (file)
@@ -417,7 +417,7 @@ void Texture::setImage(egl::Context *context, GLenum format, GLenum type, const
 
 void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, egl::Image *image)
 {
-       if(pixels && image)
+       if(pixels && image && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
        {
                GLsizei depth = (getTarget() == GL_TEXTURE_3D_OES || getTarget() == GL_TEXTURE_2D_ARRAY) ? image->getDepth() : 1;
                image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), depth, imageSize, pixels);
@@ -469,7 +469,7 @@ void Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GL
                return error(GL_INVALID_OPERATION);
        }
 
-       if(pixels)
+       if(pixels && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
        {
                image->loadCompressedData(xoffset, yoffset, zoffset, width, height, depth, imageSize, pixels);
        }