Skip to content

Commit

Permalink
[d3d8/9] Add several Set/GetPrivateData validations
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Oct 13, 2024
1 parent c5e645d commit e03ab1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/d3d8/d3d8_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace dxvk {
DWORD Flags) final {
HRESULT hr;
if (Flags & D3DSPD_IUNKNOWN) {
if(unlikely(SizeOfData != sizeof(IUnknown*)))
return D3DERR_INVALIDCALL;
IUnknown* unknown =
const_cast<IUnknown*>(
reinterpret_cast<const IUnknown*>(pData));
Expand All @@ -39,7 +41,7 @@ namespace dxvk {
hr = m_privateData.setData(
refguid, SizeOfData, pData);

if (FAILED(hr))
if (unlikely(FAILED(hr)))
return D3DERR_INVALIDCALL;

return D3D_OK;
Expand All @@ -49,19 +51,28 @@ namespace dxvk {
REFGUID refguid,
void* pData,
DWORD* pSizeOfData) final {
if (unlikely(pData == nullptr && pSizeOfData == nullptr))
return D3DERR_NOTFOUND;

HRESULT hr = m_privateData.getData(
refguid, reinterpret_cast<UINT*>(pSizeOfData), pData);

if (FAILED(hr))
return D3DERR_INVALIDCALL;
if (unlikely(FAILED(hr))) {
if(hr == DXGI_ERROR_MORE_DATA)
return D3DERR_MOREDATA;
else if (hr == DXGI_ERROR_NOT_FOUND)
return D3DERR_NOTFOUND;
else
return D3DERR_INVALIDCALL;
}

return D3D_OK;
}

HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) final {
HRESULT hr = m_privateData.setData(refguid, 0, nullptr);

if (FAILED(hr))
if (unlikely(FAILED(hr)))
return D3DERR_INVALIDCALL;

return D3D_OK;
Expand Down
19 changes: 15 additions & 4 deletions src/d3d9/d3d9_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace dxvk {
DWORD Flags) final {
HRESULT hr;
if (Flags & D3DSPD_IUNKNOWN) {
if(unlikely(SizeOfData != sizeof(IUnknown*)))
return D3DERR_INVALIDCALL;
IUnknown* unknown =
const_cast<IUnknown*>(
reinterpret_cast<const IUnknown*>(pData));
Expand All @@ -32,7 +34,7 @@ namespace dxvk {
hr = m_privateData.setData(
refguid, SizeOfData, pData);

if (FAILED(hr))
if (unlikely(FAILED(hr)))
return D3DERR_INVALIDCALL;

return D3D_OK;
Expand All @@ -42,19 +44,28 @@ namespace dxvk {
REFGUID refguid,
void* pData,
DWORD* pSizeOfData) final {
if (unlikely(pData == nullptr && pSizeOfData == nullptr))
return D3DERR_NOTFOUND;

HRESULT hr = m_privateData.getData(
refguid, reinterpret_cast<UINT*>(pSizeOfData), pData);

if (FAILED(hr))
return D3DERR_INVALIDCALL;
if (unlikely(FAILED(hr))) {
if(hr == DXGI_ERROR_MORE_DATA)
return D3DERR_MOREDATA;
else if (hr == DXGI_ERROR_NOT_FOUND)
return D3DERR_NOTFOUND;
else
return D3DERR_INVALIDCALL;
}

return D3D_OK;
}

HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) final {
HRESULT hr = m_privateData.setData(refguid, 0, nullptr);

if (FAILED(hr))
if (unlikely(FAILED(hr)))
return D3DERR_INVALIDCALL;

return D3D_OK;
Expand Down

0 comments on commit e03ab1b

Please sign in to comment.