[PATCH vkd3d 5/8] vkd3d: Validate box in d3d12_command_list_CopyTextureRegion().

Józef Kucia joseph.kucia at gmail.com
Mon Mar 18 04:03:02 CDT 2019


From: Józef Kucia <jkucia at codeweavers.com>

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 libs/vkd3d/command.c       | 13 +++++++++++++
 libs/vkd3d/utils.c         | 10 ++++++++++
 libs/vkd3d/vkd3d_private.h |  1 +
 tests/d3d12.c              |  5 +++++
 4 files changed, 29 insertions(+)

diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index 0ce540a7d8a7..33dfcaf1ad41 100644
--- a/libs/vkd3d/command.c
+++ b/libs/vkd3d/command.c
@@ -2715,6 +2715,13 @@ static void d3d12_command_list_copy_incompatible_texture_region(struct d3d12_com
             VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &buffer_image_copy));
 }
 
+static bool validate_d3d12_box(const D3D12_BOX *box)
+{
+    return box->right > box->left
+            && box->bottom > box->top
+            && box->back > box->front;
+}
+
 static void STDMETHODCALLTYPE d3d12_command_list_CopyTextureRegion(ID3D12GraphicsCommandList1 *iface,
         const D3D12_TEXTURE_COPY_LOCATION *dst, UINT dst_x, UINT dst_y, UINT dst_z,
         const D3D12_TEXTURE_COPY_LOCATION *src, const D3D12_BOX *src_box)
@@ -2729,6 +2736,12 @@ static void STDMETHODCALLTYPE d3d12_command_list_CopyTextureRegion(ID3D12Graphic
     TRACE("iface %p, dst %p, dst_x %u, dst_y %u, dst_z %u, src %p, src_box %p.\n",
             iface, dst, dst_x, dst_y, dst_z, src, src_box);
 
+    if (src_box && !validate_d3d12_box(src_box))
+    {
+        WARN("Empty box %s.\n", debug_d3d12_box(src_box));
+        return;
+    }
+
     vk_procs = &list->device->vk_procs;
 
     dst_resource = unsafe_impl_from_ID3D12Resource(dst->pResource);
diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c
index 0abb62fd7fbc..e0af3f6e2dfd 100644
--- a/libs/vkd3d/utils.c
+++ b/libs/vkd3d/utils.c
@@ -321,6 +321,16 @@ HRESULT return_interface(void *iface, REFIID iface_iid,
     return hr;
 }
 
+const char *debug_d3d12_box(const D3D12_BOX *box)
+{
+    if (!box)
+        return "(null)";
+
+    return vkd3d_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
+            box->left, box->top, box->front,
+            box->right, box->bottom, box->back);
+}
+
 const char *debug_vk_extent_3d(VkExtent3D extent)
 {
     return vkd3d_dbg_sprintf("(%u, %u, %u)",
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index b4727a20a4df..a6ada4b4e68f 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -1015,6 +1015,7 @@ static inline bool is_cpu_accessible_heap(const D3D12_HEAP_PROPERTIES *propertie
 HRESULT return_interface(void *iface, REFIID iface_iid,
         REFIID requested_iid, void **object) DECLSPEC_HIDDEN;
 
+const char *debug_d3d12_box(const D3D12_BOX *box) DECLSPEC_HIDDEN;
 const char *debug_vk_extent_3d(VkExtent3D extent) DECLSPEC_HIDDEN;
 const char *debug_vk_memory_heap_flags(VkMemoryHeapFlags flags) DECLSPEC_HIDDEN;
 const char *debug_vk_memory_property_flags(VkMemoryPropertyFlags flags) DECLSPEC_HIDDEN;
diff --git a/tests/d3d12.c b/tests/d3d12.c
index 825a64787714..d21be3ff5cd1 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -20933,6 +20933,11 @@ static void test_copy_texture_buffer(void)
     ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
             &dst_location, 32, 0, 0, &src_location, &box);
 
+    /* empty box */
+    set_box(&box, 128, 0, 0, 32, 32, 1);
+    ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
+            &dst_location, 0, 0, 0, &src_location, &box);
+
     for (i = 0; i < ARRAY_SIZE(dst_buffers); ++i)
     {
         transition_resource_state(command_list, dst_buffers[i],
-- 
2.19.2




More information about the wine-devel mailing list