Vulkan: Make sure the default uniform info arrays match indices.

When inserting uniform layout info into the default uniform block, the array
sizes need to match but insertion was skipped when the uniform was a sampler.

This caused heap corruption when uniform data was written to the wrong offset
in the buffer.

BUG=angleproject:2859

Change-Id: Ia58a68870e2a4805391266dfe73fe8c8d238931d
Reviewed-on: https://chromium-review.googlesource.com/1249562
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/ProgramVk.cpp b/src/libANGLE/renderer/vulkan/ProgramVk.cpp
index 5175b2b..70c0cca 100644
--- a/src/libANGLE/renderer/vulkan/ProgramVk.cpp
+++ b/src/libANGLE/renderer/vulkan/ProgramVk.cpp
@@ -68,6 +68,7 @@
     {
         uint32_t arrayOffset = arrayIndex * layoutInfo.arrayStride;
         uint8_t *writePtr    = dst + arrayOffset;
+        ASSERT(writePtr + (elementSize * count) <= uniformData->data() + uniformData->size());
         memcpy(writePtr, v, elementSize * count);
     }
     else
@@ -80,6 +81,7 @@
             const int arrayOffset = writeIndex * layoutInfo.arrayStride;
             uint8_t *writePtr     = dst + arrayOffset;
             const T *readPtr      = v + (readIndex * componentCount);
+            ASSERT(writePtr + elementSize <= uniformData->data() + uniformData->size());
             memcpy(writePtr, readPtr, elementSize);
         }
     }
@@ -372,30 +374,29 @@
         if (location.used() && !location.ignored)
         {
             const auto &uniform = uniforms[location.index];
-
-            if (uniform.isSampler())
-                continue;
-
-            std::string uniformName = uniform.name;
-            if (uniform.isArray())
+            if (!uniform.isSampler())
             {
-                // Gets the uniform name without the [0] at the end.
-                uniformName = gl::ParseResourceName(uniformName, nullptr);
-            }
-
-            bool found = false;
-
-            for (vk::ShaderType shaderType : vk::AllShaderTypes())
-            {
-                auto it = layoutMap[shaderType].find(uniformName);
-                if (it != layoutMap[shaderType].end())
+                std::string uniformName = uniform.name;
+                if (uniform.isArray())
                 {
-                    found                  = true;
-                    layoutInfo[shaderType] = it->second;
+                    // Gets the uniform name without the [0] at the end.
+                    uniformName = gl::ParseResourceName(uniformName, nullptr);
                 }
-            }
 
-            ASSERT(found);
+                bool found = false;
+
+                for (vk::ShaderType shaderType : vk::AllShaderTypes())
+                {
+                    auto it = layoutMap[shaderType].find(uniformName);
+                    if (it != layoutMap[shaderType].end())
+                    {
+                        found                  = true;
+                        layoutInfo[shaderType] = it->second;
+                    }
+                }
+
+                ASSERT(found);
+            }
         }
 
         for (vk::ShaderType shaderType : vk::AllShaderTypes())