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
// 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
// fourth tests. We'll use this value later in rendering.
GLint stencilBitCount;
GLint stencilBitCount = 0;
glGetIntegerv(GL_STENCIL_BITS, &stencilBitCount);
stencilValues[3] = ~(((1 << stencilBitCount) - 1) & 0x1) & 0xff;
......
......@@ -8,6 +8,8 @@
#include "libANGLE/queryconversions.h"
#include <vector>
#include "libANGLE/Context.h"
#include "common/utilities.h"
......@@ -101,59 +103,43 @@ void CastStateValues(Context *context, GLenum nativeType, GLenum pname,
{
if (nativeType == GL_INT)
{
GLint *intParams = NULL;
intParams = new GLint[numParams];
context->getIntegerv(pname, intParams);
std::vector<GLint> intParams(numParams, 0);
context->getIntegerv(pname, intParams.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = CastStateValue<QueryT>(pname, intParams[i]);
}
delete [] intParams;
}
else if (nativeType == GL_BOOL)
{
GLboolean *boolParams = NULL;
boolParams = new GLboolean[numParams];
context->getBooleanv(pname, boolParams);
std::vector<GLboolean> boolParams(numParams, GL_FALSE);
context->getBooleanv(pname, boolParams.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = (boolParams[i] == GL_FALSE ? static_cast<QueryT>(0) : static_cast<QueryT>(1));
}
delete [] boolParams;
}
else if (nativeType == GL_FLOAT)
{
GLfloat *floatParams = NULL;
floatParams = new GLfloat[numParams];
context->getFloatv(pname, floatParams);
std::vector<GLfloat> floatParams(numParams, 0.0f);
context->getFloatv(pname, floatParams.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = CastStateValue<QueryT>(pname, floatParams[i]);
}
delete [] floatParams;
}
else if (nativeType == GL_INT_64_ANGLEX)
{
GLint64 *int64Params = NULL;
int64Params = new GLint64[numParams];
context->getInteger64v(pname, int64Params);
std::vector<GLint64> int64Params(numParams, 0);
context->getInteger64v(pname, int64Params.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = CastStateValue<QueryT>(pname, int64Params[i]);
}
delete [] int64Params;
}
else UNREACHABLE();
}
......
......@@ -788,14 +788,11 @@ void FunctionsGL::initialize()
}
// Check the context profile
profile = 0;
if (isAtLeastGL(gl::Version(3, 2)))
{
getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
}
else
{
profile = 0;
}
// clang-format off
......
......@@ -50,7 +50,7 @@ VertexArrayGL::VertexArrayGL(const VertexArray::Data &data,
mFunctions->genVertexArrays(1, &mVertexArrayID);
// Set the cached vertex attribute array size
GLint maxVertexAttribs;
GLint maxVertexAttribs = 0;
mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
mAppliedAttributes.resize(maxVertexAttribs);
}
......
......@@ -111,35 +111,35 @@ static gl::TextureCaps GenerateTextureFormatCaps(const FunctionsGL *functions, G
static GLint QuerySingleGLInt(const FunctionsGL *functions, GLenum name)
{
GLint result;
GLint result = 0;
functions->getIntegerv(name, &result);
return result;
}
static GLint QueryGLIntRange(const FunctionsGL *functions, GLenum name, size_t index)
{
GLint result[2];
GLint result[2] = {};
functions->getIntegerv(name, result);
return result[index];
}
static GLint64 QuerySingleGLInt64(const FunctionsGL *functions, GLenum name)
{
GLint64 result;
GLint64 result = 0;
functions->getInteger64v(name, &result);
return result;
}
static GLfloat QuerySingleGLFloat(const FunctionsGL *functions, GLenum name)
{
GLfloat result;
GLfloat result = 0.0f;
functions->getFloatv(name, &result);
return result;
}
static GLfloat QueryGLFloatRange(const FunctionsGL *functions, GLenum name, size_t index)
{
GLfloat result[2];
GLfloat result[2] = {};
functions->getFloatv(name, result);
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