Validate that attrib offsets don't overflow buffers.

During draw calls, we wouldn't add the current attrib offset to the
required draw call size when checking attributes. This could lead to
us producing warnings in the D3D11 runtime, and miss returning some
errors.

BUG=angleproject:1339

Change-Id: I03555be396df46f83d96dfb34fbcb145169625e8
Reviewed-on: https://chromium-review.googlesource.com/331807
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 12c7612..c06eb7a 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -68,13 +68,16 @@
                     GLint64 attribSize =
                         static_cast<GLint64>(ComputeVertexAttributeTypeSize(attrib));
                     GLint64 attribDataSize = (maxVertexElement - 1) * attribStride + attribSize;
+                    GLint64 attribOffset   = static_cast<GLint64>(attrib.offset);
 
                     // [OpenGL ES 3.0.2] section 2.9.4 page 40:
                     // We can return INVALID_OPERATION if our vertex attribute does not have
                     // enough backing data.
-                    if (attribDataSize > buffer->getSize())
+                    if (attribDataSize + attribOffset > buffer->getSize())
                     {
-                        context->recordError(Error(GL_INVALID_OPERATION));
+                        context->recordError(
+                            Error(GL_INVALID_OPERATION,
+                                  "Vertex buffer is not big enough for the draw call"));
                         return false;
                     }
                 }
@@ -2017,7 +2020,7 @@
         return false;
     }
 
-    if (!ValidateDrawAttribs(context, primcount, static_cast<GLsizei>(indexRangeOut->end)))
+    if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRangeOut->vertexCount())))
     {
         return false;
     }