Add checks for FBO attachment layer.

We would allow the app to attach layers that were out-of-bounds. Fix
this by checking against the underlying resource dimensions. Also
rework the code a bit to clean up the texture size query, which is
available from the ImageDesc.

BUG=angleproject:869

Change-Id: I984f1db16daea6ca650d795884d8ec2cb8f05ebb
Reviewed-on: https://chromium-review.googlesource.com/313991
Tryjob-Request: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 547f548..4af2ac0 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -543,9 +543,11 @@
                           GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
                           GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
 {
-    if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 ||
-        dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() ||
-        srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight())
+    const Extents &writeSize = writeBuffer->getSize();
+    const Extents &readSize  = readBuffer->getSize();
+
+    if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width ||
+        dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height)
     {
         return true;
     }
@@ -553,9 +555,8 @@
     {
         const Rectangle &scissor = context->getState().getScissor();
 
-        return scissor.x > 0 || scissor.y > 0 ||
-               scissor.width < writeBuffer->getWidth() ||
-               scissor.height < writeBuffer->getHeight();
+        return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width ||
+               scissor.height < writeSize.height;
     }
     else
     {