Commit 2363356f by Geoff Lang Committed by Commit Bot

Make sure index ranges outside of the GLint range are handled correctly.

IndexRange uses size_t values but DrawCallParams::mFirstVertex is a GLint. This makes sure all casting is safe. BUG=864528 Change-Id: Iaa95019615af4d3f79b12bbcb0df13b44cb54339 Reviewed-on: https://chromium-review.googlesource.com/1140898Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 35bc74d6
......@@ -1470,6 +1470,51 @@ TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Test that index values outside of the 32-bit integer range do not read out of bounds
TEST_P(WebGLCompatibilityTest, LargeIndexRange)
{
ANGLE_SKIP_TEST_IF(!ensureExtensionEnabled("GL_OES_element_index_uint"));
const std::string &vert =
"attribute vec4 a_Position;\n"
"void main()\n"
"{\n"
" gl_Position = a_Position;\n"
"}\n";
ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
glUseProgram(program.get());
glEnableVertexAttribArray(glGetAttribLocation(program, "a_Position"));
constexpr float kVertexData[] = {
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
};
GLBuffer vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(kVertexData), kVertexData, GL_STREAM_DRAW);
constexpr GLuint kMaxIntAsGLuint = static_cast<GLuint>(std::numeric_limits<GLint>::max());
constexpr GLuint kIndexData[] = {
kMaxIntAsGLuint, kMaxIntAsGLuint + 1, kMaxIntAsGLuint + 2, kMaxIntAsGLuint + 3,
};
GLBuffer indexBuffer;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(kIndexData), kIndexData, GL_DYNAMIC_DRAW);
EXPECT_GL_NO_ERROR();
// First index is representable as 32-bit int but second is not
glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, 0);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Neither index is representable as 32-bit int
glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, reinterpret_cast<void *>(sizeof(GLuint) * 2));
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Test for drawing with a null index buffer
TEST_P(WebGLCompatibilityTest, NullIndexBuffer)
{
......
......@@ -838,6 +838,16 @@ bool ANGLETestBase::extensionRequestable(const std::string &extName)
reinterpret_cast<const char *>(glGetString(GL_REQUESTABLE_EXTENSIONS_ANGLE)), extName);
}
bool ANGLETestBase::ensureExtensionEnabled(const std::string &extName)
{
if (extensionEnabled("GL_ANGLE_request_extension") && extensionRequestable(extName))
{
glRequestExtensionANGLE(extName.c_str());
}
return extensionEnabled(extName);
}
bool ANGLETestBase::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
{
return CheckExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
......
......@@ -323,6 +323,7 @@ class ANGLETestBase
static GLuint compileShader(GLenum type, const std::string &source);
static bool extensionEnabled(const std::string &extName);
static bool extensionRequestable(const std::string &extName);
static bool ensureExtensionEnabled(const std::string &extName);
static bool eglClientExtensionEnabled(const std::string &extName);
static bool eglDeviceExtensionEnabled(EGLDeviceEXT device, const std::string &extName);
......
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