From: Alexis Hetu Date: Wed, 27 Sep 2017 18:43:38 +0000 (-0400) Subject: Prevent division by 0 X-Git-Tag: android-x86-7.1-r3~360 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=444b04ad7419efdaaad3a0caa0077eadca18c89f;p=android-x86%2Fexternal-swiftshader.git 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/12648 Tested-by: Alexis Hétu Reviewed-by: Nicolas Capens --- diff --git a/src/OpenGL/libGL/Texture.cpp b/src/OpenGL/libGL/Texture.cpp index e0756d2f5..38b9cc643 100644 --- a/src/OpenGL/libGL/Texture.cpp +++ b/src/OpenGL/libGL/Texture.cpp @@ -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); } diff --git a/src/OpenGL/libGLES_CM/Texture.cpp b/src/OpenGL/libGLES_CM/Texture.cpp index 80a388691..18e9fbfbd 100644 --- a/src/OpenGL/libGLES_CM/Texture.cpp +++ b/src/OpenGL/libGLES_CM/Texture.cpp @@ -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); } diff --git a/src/OpenGL/libGLESv2/Texture.cpp b/src/OpenGL/libGLESv2/Texture.cpp index b0a46a583..0b09e1103 100644 --- a/src/OpenGL/libGLESv2/Texture.cpp +++ b/src/OpenGL/libGLESv2/Texture.cpp @@ -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); }