Validate level exists for TexSubImage calls.

Before validating the texture format, verify that the texture level already
exists in glTexSubImage calls.

BUG=602737

Change-Id: I0d83c7d43c7b358abdb59583dc83265df70c13b5
Reviewed-on: https://chromium-review.googlesource.com/411361
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/libANGLE/validationES3.cpp b/src/libANGLE/validationES3.cpp
index 3b3a568..87627a7 100644
--- a/src/libANGLE/validationES3.cpp
+++ b/src/libANGLE/validationES3.cpp
@@ -168,6 +168,12 @@
     // Validate texture formats
     GLenum actualInternalFormat =
         isSubImage ? texture->getFormat(target, level).asSized() : internalformat;
+    if (isSubImage && actualInternalFormat == GL_NONE)
+    {
+        context->handleError(Error(GL_INVALID_OPERATION, "Texture level does not exist."));
+        return false;
+    }
+
     const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualInternalFormat);
     if (isCompressed)
     {