From f52dc8a89a19ba799f52dfbbdf4f7f0b4e6cf879 Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Fri, 15 Aug 2025 18:48:01 -0500 Subject: [PATCH] vkd3d-utils: Null-terminate the output of D3DDisassemble(). --- libs/vkd3d-utils/vkd3d_utils_main.c | 4 +++- tests/hlsl_d3d12.c | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index 71fcc56ca..7fed86f4f 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -1034,7 +1034,9 @@ HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T data_size, return hresult_from_vkd3d_result(ret); } - if (FAILED(hr = vkd3d_blob_create((void *)output.code, output.size, blob))) + /* vkd3d-shader output is null-terminated, but the null terminator isn't + * included in the size. Increase the size to account for that. */ + if (FAILED(hr = vkd3d_blob_create((void *)output.code, output.size + 1, blob))) vkd3d_shader_free_shader_code(&output); return hr; diff --git a/tests/hlsl_d3d12.c b/tests/hlsl_d3d12.c index d5f2f4a29..95df3a5e4 100644 --- a/tests/hlsl_d3d12.c +++ b/tests/hlsl_d3d12.c @@ -3495,9 +3495,9 @@ static void test_disassemble_shader(void) ok(hr == S_OK, "Got hr %#x.\n", hr); code = ID3D10Blob_GetBufferPointer(blob); size = ID3D10Blob_GetBufferSize(blob); - todo ok(size == strlen(code) + 1, "Expected size %u, got %u.\n", + ok(size == strlen(code) + 1, "Expected size %u, got %u.\n", (unsigned int)strlen(code) + 1, (unsigned int)size); - todo ok(code[size - 1] == 0, "Expected null termination, got %#x.\n", code[size - 1]); + ok(code[size - 1] == 0, "Expected null termination, got %#x.\n", code[size - 1]); ID3D10Blob_Release(blob); hr = D3DDisassemble(vs_3_0, sizeof(vs_3_0), 0, NULL, &blob); @@ -3513,9 +3513,9 @@ static void test_disassemble_shader(void) ok(hr == S_OK, "Got hr %#x.\n", hr); code = ID3D10Blob_GetBufferPointer(blob); size = ID3D10Blob_GetBufferSize(blob); - todo ok(size == strlen(code) + 1, "Expected size %u, got %u.\n", + ok(size == strlen(code) + 1, "Expected size %u, got %u.\n", (unsigned int)strlen(code) + 1, (unsigned int)size); - todo ok(code[size - 1] == 0, "Expected null termination, got %#x.\n", code[size - 1]); + ok(code[size - 1] == 0, "Expected null termination, got %#x.\n", code[size - 1]); ID3D10Blob_Release(blob); }