Commit 2426d5fe by Geoff Lang Committed by Shannon Woods

Protect against integer overflows when generating index buffers for line loop…

Protect against integer overflows when generating index buffers for line loop and triangle fan drawing. Issue 444 Signed-off-by: Jamie Madil Signed-off-by: Shannon Woods Author: Geoff Lang
parent a240a2f9
...@@ -3253,7 +3253,11 @@ void Context::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, in ...@@ -3253,7 +3253,11 @@ void Context::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, in
if (supports32bitIndices()) if (supports32bitIndices())
{ {
const int spaceNeeded = (count + 1) * sizeof(unsigned int); if (static_cast<unsigned int>(count + 1) > (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int)))
{
return error(GL_OUT_OF_MEMORY);
}
const unsigned int spaceNeeded = (count + 1) * sizeof(unsigned int);
if (!mLineLoopIB) if (!mLineLoopIB)
{ {
...@@ -3310,7 +3314,11 @@ void Context::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, in ...@@ -3310,7 +3314,11 @@ void Context::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, in
} }
else else
{ {
const int spaceNeeded = (count + 1) * sizeof(unsigned short); if (static_cast<unsigned short>(count + 1) > (std::numeric_limits<unsigned short>::max() / sizeof(unsigned short)))
{
return error(GL_OUT_OF_MEMORY);
}
const unsigned int spaceNeeded = (count + 1) * sizeof(unsigned short);
if (!mLineLoopIB) if (!mLineLoopIB)
{ {
......
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