mirror of
https://github.com/microsoft/DirectXTex.git
synced 2026-02-04 04:16:12 +01:00
texconv: Fix PFM reader to avoid overread of buffer (#413)
* texconv: Fix PFM reader to avoid overread of buffer * More code review * Max memory usage * YAML fix
This commit is contained in:
@@ -687,11 +687,16 @@ namespace
|
||||
_In_ ID3D12Resource* pSource,
|
||||
UINT64 srcPitch,
|
||||
const D3D12_RESOURCE_DESC& desc,
|
||||
ComPtr<ID3D12Resource>& pStaging,
|
||||
_COM_Outptr_ ID3D12Resource** pStaging,
|
||||
D3D12_RESOURCE_STATES beforeState,
|
||||
D3D12_RESOURCE_STATES afterState) noexcept
|
||||
{
|
||||
if (!pCommandQ || !pSource)
|
||||
if (pStaging)
|
||||
{
|
||||
*pStaging = nullptr;
|
||||
}
|
||||
|
||||
if (!pCommandQ || !pSource || !pStaging)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D)
|
||||
@@ -709,7 +714,8 @@ namespace
|
||||
if (SUCCEEDED(hr) && sourceHeapProperties.Type == D3D12_HEAP_TYPE_READBACK)
|
||||
{
|
||||
// Handle case where the source is already a staging texture we can use directly
|
||||
pStaging = pSource;
|
||||
*pStaging = pSource;
|
||||
pSource->AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -801,11 +807,11 @@ namespace
|
||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
nullptr,
|
||||
IID_ID3D12Resource,
|
||||
reinterpret_cast<void**>(pStaging.ReleaseAndGetAddressOf()));
|
||||
reinterpret_cast<void**>(pStaging));
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
assert(pStaging);
|
||||
assert(*pStaging);
|
||||
|
||||
// Transition the resource if necessary
|
||||
TransitionResource(commandList.Get(), pSource, beforeState, D3D12_RESOURCE_STATE_COPY_SOURCE);
|
||||
@@ -818,7 +824,7 @@ namespace
|
||||
bufferFootprint.Footprint.RowPitch = static_cast<UINT>(srcPitch);
|
||||
bufferFootprint.Footprint.Format = desc.Format;
|
||||
|
||||
const CD3DX12_TEXTURE_COPY_LOCATION copyDest(pStaging.Get(), bufferFootprint);
|
||||
const CD3DX12_TEXTURE_COPY_LOCATION copyDest(*pStaging, bufferFootprint);
|
||||
const CD3DX12_TEXTURE_COPY_LOCATION copySrc(copySource.Get(), 0);
|
||||
|
||||
// Copy the texture
|
||||
@@ -929,7 +935,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
|
||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||
|
||||
ComPtr<ID3D12Resource> pStaging;
|
||||
HRESULT hr = CaptureTexture(device.Get(), pCommandQ, pSource, dstRowPitch, desc, pStaging, beforeState, afterState);
|
||||
HRESULT hr = CaptureTexture(device.Get(), pCommandQ, pSource, dstRowPitch, desc, pStaging.GetAddressOf(), beforeState, afterState);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
@@ -1157,7 +1163,7 @@ HRESULT DirectX::SaveWICTextureToFile(
|
||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||
|
||||
ComPtr<ID3D12Resource> pStaging;
|
||||
HRESULT hr = CaptureTexture(device.Get(), pCommandQ, pSource, dstRowPitch, desc, pStaging, beforeState, afterState);
|
||||
HRESULT hr = CaptureTexture(device.Get(), pCommandQ, pSource, dstRowPitch, desc, pStaging.GetAddressOf(), beforeState, afterState);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user