Commit 444b04ad by Alexis Hetu Committed by Alexis Hétu

Prevent division by 0

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/12648Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 560232a6
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment