d3dx9: Validate the size of a volume texture in D3DXGetImageInfoFromFile.

This commit is contained in:
Józef Kucia 2012-07-03 16:06:43 +02:00 committed by Alexandre Julliard
parent 563355d651
commit 0ad6af9caa
2 changed files with 7 additions and 4 deletions

View File

@ -317,8 +317,8 @@ static HRESULT calculate_dds_surface_size(const D3DXIMAGE_INFO *img_info,
static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAGE_INFO *info) static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAGE_INFO *info)
{ {
UINT i; UINT i;
UINT faces = 0; UINT faces = 1;
UINT width, height; UINT width, height, depth;
const struct dds_header *header = buffer; const struct dds_header *header = buffer;
UINT expected_length = 0; UINT expected_length = 0;
@ -347,6 +347,7 @@ static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAG
else if (header->caps2 & DDS_CAPS2_CUBEMAP) else if (header->caps2 & DDS_CAPS2_CUBEMAP)
{ {
DWORD face; DWORD face;
faces = 0;
for (face = DDS_CAPS2_CUBEMAP_POSITIVEX; face <= DDS_CAPS2_CUBEMAP_NEGATIVEZ; face <<= 1) for (face = DDS_CAPS2_CUBEMAP_POSITIVEX; face <= DDS_CAPS2_CUBEMAP_NEGATIVEZ; face <<= 1)
{ {
if (header->caps2 & face) if (header->caps2 & face)
@ -356,20 +357,22 @@ static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAG
} }
else else
{ {
faces = 1;
info->ResourceType = D3DRTYPE_TEXTURE; info->ResourceType = D3DRTYPE_TEXTURE;
} }
/* calculate the expected length */ /* calculate the expected length */
width = info->Width; width = info->Width;
height = info->Height; height = info->Height;
depth = info->Depth;
for (i = 0; i < info->MipLevels; i++) for (i = 0; i < info->MipLevels; i++)
{ {
UINT pitch, size = 0; UINT pitch, size = 0;
calculate_dds_surface_size(info, width, height, &pitch, &size); calculate_dds_surface_size(info, width, height, &pitch, &size);
size *= depth;
expected_length += size; expected_length += size;
width = max(1, width / 2); width = max(1, width / 2);
height = max(1, height / 2); height = max(1, height / 2);
depth = max(1, depth / 2);
} }
expected_length *= faces; expected_length *= faces;

View File

@ -544,7 +544,7 @@ static void test_D3DXGetImageInfo(void)
ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info); hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info);
todo_wine ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
/* cleanup */ /* cleanup */