From 49f4fedd0bf98e3927dcd10cde514f20a2ab0437 Mon Sep 17 00:00:00 2001 From: Michael Lentine Date: Thu, 31 Mar 2016 14:45:20 -0500 Subject: [PATCH] layers: Adding attachment checks to make sure they aren't out of range. --- layers/core_validation.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index b79114e..8ebc10b 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -9420,6 +9420,13 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice devic const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i]; for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { uint32_t attachment = subpass.pColorAttachments[j].attachment; + if (attachment >= pCreateInfo->attachmentCount) { + skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, + __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS", + "Color attachment %d cannot be greater than the total number of attachments %d.", + attachment, pCreateInfo->attachmentCount); + continue; + } if (attachment_first_read.count(attachment)) continue; attachment_first_read.insert(std::make_pair(attachment, false)); @@ -9427,6 +9434,13 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice devic } if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { uint32_t attachment = subpass.pDepthStencilAttachment->attachment; + if (attachment >= pCreateInfo->attachmentCount) { + skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, + __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS", + "Depth stencil attachment %d cannot be greater than the total number of attachments %d.", + attachment, pCreateInfo->attachmentCount); + continue; + } if (attachment_first_read.count(attachment)) continue; attachment_first_read.insert(std::make_pair(attachment, false)); @@ -9434,6 +9448,13 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice devic } for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { uint32_t attachment = subpass.pInputAttachments[j].attachment; + if (attachment >= pCreateInfo->attachmentCount) { + skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, + __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS", + "Input attachment %d cannot be greater than the total number of attachments %d.", + attachment, pCreateInfo->attachmentCount); + continue; + } if (attachment_first_read.count(attachment)) continue; attachment_first_read.insert(std::make_pair(attachment, true)); -- 2.7.4