Commit bb7740cc by hendrikw Committed by Hendrik Wagenaar

angle: prevent huge allocations when GL_MAX_VERTEX_ATTRIBS fails

I'm not sure why yet, but when using angle in skia, getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs) sometimes fails, and when that happens we attempt to allocate and array with the size of maxVertexAttribs, which is uninitialized, which could be huge. Prevent this by initializing the variable. Also sweep through other similar calls and ensure that these use initialized values (test code has not been updated) BUG=skia:4380 Change-Id: If1f3cf72f2b2829ad3933637af8778d574a20f61 Reviewed-on: https://chromium-review.googlesource.com/307239Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Tryjob-Request: Dian Xiang <dianx@google.com> Tested-by: 's avatarHendrik Wagenaar <hendrikw@chromium.org>
parent 9c970870
...@@ -204,7 +204,7 @@ class StencilOperationsSample : public SampleApplication ...@@ -204,7 +204,7 @@ class StencilOperationsSample : public SampleApplication
// Since we don't know at compile time how many stencil bits are present, we'll // Since we don't know at compile time how many stencil bits are present, we'll
// query, and update the value correct value in the stencilValues arrays for the // query, and update the value correct value in the stencilValues arrays for the
// fourth tests. We'll use this value later in rendering. // fourth tests. We'll use this value later in rendering.
GLint stencilBitCount; GLint stencilBitCount = 0;
glGetIntegerv(GL_STENCIL_BITS, &stencilBitCount); glGetIntegerv(GL_STENCIL_BITS, &stencilBitCount);
stencilValues[3] = ~(((1 << stencilBitCount) - 1) & 0x1) & 0xff; stencilValues[3] = ~(((1 << stencilBitCount) - 1) & 0x1) & 0xff;
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "libANGLE/queryconversions.h" #include "libANGLE/queryconversions.h"
#include <vector>
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
#include "common/utilities.h" #include "common/utilities.h"
...@@ -101,59 +103,43 @@ void CastStateValues(Context *context, GLenum nativeType, GLenum pname, ...@@ -101,59 +103,43 @@ void CastStateValues(Context *context, GLenum nativeType, GLenum pname,
{ {
if (nativeType == GL_INT) if (nativeType == GL_INT)
{ {
GLint *intParams = NULL; std::vector<GLint> intParams(numParams, 0);
intParams = new GLint[numParams]; context->getIntegerv(pname, intParams.data());
context->getIntegerv(pname, intParams);
for (unsigned int i = 0; i < numParams; ++i) for (unsigned int i = 0; i < numParams; ++i)
{ {
outParams[i] = CastStateValue<QueryT>(pname, intParams[i]); outParams[i] = CastStateValue<QueryT>(pname, intParams[i]);
} }
delete [] intParams;
} }
else if (nativeType == GL_BOOL) else if (nativeType == GL_BOOL)
{ {
GLboolean *boolParams = NULL; std::vector<GLboolean> boolParams(numParams, GL_FALSE);
boolParams = new GLboolean[numParams]; context->getBooleanv(pname, boolParams.data());
context->getBooleanv(pname, boolParams);
for (unsigned int i = 0; i < numParams; ++i) for (unsigned int i = 0; i < numParams; ++i)
{ {
outParams[i] = (boolParams[i] == GL_FALSE ? static_cast<QueryT>(0) : static_cast<QueryT>(1)); outParams[i] = (boolParams[i] == GL_FALSE ? static_cast<QueryT>(0) : static_cast<QueryT>(1));
} }
delete [] boolParams;
} }
else if (nativeType == GL_FLOAT) else if (nativeType == GL_FLOAT)
{ {
GLfloat *floatParams = NULL; std::vector<GLfloat> floatParams(numParams, 0.0f);
floatParams = new GLfloat[numParams]; context->getFloatv(pname, floatParams.data());
context->getFloatv(pname, floatParams);
for (unsigned int i = 0; i < numParams; ++i) for (unsigned int i = 0; i < numParams; ++i)
{ {
outParams[i] = CastStateValue<QueryT>(pname, floatParams[i]); outParams[i] = CastStateValue<QueryT>(pname, floatParams[i]);
} }
delete [] floatParams;
} }
else if (nativeType == GL_INT_64_ANGLEX) else if (nativeType == GL_INT_64_ANGLEX)
{ {
GLint64 *int64Params = NULL; std::vector<GLint64> int64Params(numParams, 0);
int64Params = new GLint64[numParams]; context->getInteger64v(pname, int64Params.data());
context->getInteger64v(pname, int64Params);
for (unsigned int i = 0; i < numParams; ++i) for (unsigned int i = 0; i < numParams; ++i)
{ {
outParams[i] = CastStateValue<QueryT>(pname, int64Params[i]); outParams[i] = CastStateValue<QueryT>(pname, int64Params[i]);
} }
delete [] int64Params;
} }
else UNREACHABLE(); else UNREACHABLE();
} }
......
...@@ -788,14 +788,11 @@ void FunctionsGL::initialize() ...@@ -788,14 +788,11 @@ void FunctionsGL::initialize()
} }
// Check the context profile // Check the context profile
profile = 0;
if (isAtLeastGL(gl::Version(3, 2))) if (isAtLeastGL(gl::Version(3, 2)))
{ {
getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile); getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
} }
else
{
profile = 0;
}
// clang-format off // clang-format off
......
...@@ -50,7 +50,7 @@ VertexArrayGL::VertexArrayGL(const VertexArray::Data &data, ...@@ -50,7 +50,7 @@ VertexArrayGL::VertexArrayGL(const VertexArray::Data &data,
mFunctions->genVertexArrays(1, &mVertexArrayID); mFunctions->genVertexArrays(1, &mVertexArrayID);
// Set the cached vertex attribute array size // Set the cached vertex attribute array size
GLint maxVertexAttribs; GLint maxVertexAttribs = 0;
mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
mAppliedAttributes.resize(maxVertexAttribs); mAppliedAttributes.resize(maxVertexAttribs);
} }
......
...@@ -111,35 +111,35 @@ static gl::TextureCaps GenerateTextureFormatCaps(const FunctionsGL *functions, G ...@@ -111,35 +111,35 @@ static gl::TextureCaps GenerateTextureFormatCaps(const FunctionsGL *functions, G
static GLint QuerySingleGLInt(const FunctionsGL *functions, GLenum name) static GLint QuerySingleGLInt(const FunctionsGL *functions, GLenum name)
{ {
GLint result; GLint result = 0;
functions->getIntegerv(name, &result); functions->getIntegerv(name, &result);
return result; return result;
} }
static GLint QueryGLIntRange(const FunctionsGL *functions, GLenum name, size_t index) static GLint QueryGLIntRange(const FunctionsGL *functions, GLenum name, size_t index)
{ {
GLint result[2]; GLint result[2] = {};
functions->getIntegerv(name, result); functions->getIntegerv(name, result);
return result[index]; return result[index];
} }
static GLint64 QuerySingleGLInt64(const FunctionsGL *functions, GLenum name) static GLint64 QuerySingleGLInt64(const FunctionsGL *functions, GLenum name)
{ {
GLint64 result; GLint64 result = 0;
functions->getInteger64v(name, &result); functions->getInteger64v(name, &result);
return result; return result;
} }
static GLfloat QuerySingleGLFloat(const FunctionsGL *functions, GLenum name) static GLfloat QuerySingleGLFloat(const FunctionsGL *functions, GLenum name)
{ {
GLfloat result; GLfloat result = 0.0f;
functions->getFloatv(name, &result); functions->getFloatv(name, &result);
return result; return result;
} }
static GLfloat QueryGLFloatRange(const FunctionsGL *functions, GLenum name, size_t index) static GLfloat QueryGLFloatRange(const FunctionsGL *functions, GLenum name, size_t index)
{ {
GLfloat result[2]; GLfloat result[2] = {};
functions->getFloatv(name, result); functions->getFloatv(name, result);
return result[index]; return result[index];
} }
......
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