=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: vkd3d: Validate box in d3d12_command_list_CopyTextureRegion().

Alexandre Julliard julliard at winehq.org
Mon Mar 18 15:45:10 CDT 2019


Module: vkd3d
Branch: master
Commit: e9574e1f39f7ce16d30080f3f7e1c15db74cb7c5
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=e9574e1f39f7ce16d30080f3f7e1c15db74cb7c5

Author: Józef Kucia <jkucia at codeweavers.com>
Date:   Mon Mar 18 10:03:02 2019 +0100

vkd3d: Validate box in d3d12_command_list_CopyTextureRegion().

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 0ce540a..33dfcaf 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 0abb62f..e0af3f6 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 b4727a2..a6ada4b 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 825a647..d21be3f 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],




More information about the wine-cvs mailing list