Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Error Handling] Fix DxcContainerBuilder error handling #7056

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions lib/DxilContainer/DxcContainerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ HRESULT STDMETHODCALLTYPE DxcContainerBuilder::RemovePart(UINT32 fourCC) {
HRESULT STDMETHODCALLTYPE
DxcContainerBuilder::SerializeContainer(IDxcOperationResult **ppResult) {
DxcThreadMalloc TM(m_pMalloc);
if (ppResult == nullptr)
return E_INVALIDARG;

Comment on lines 107 to +110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DxcThreadMalloc TM(m_pMalloc);
if (ppResult == nullptr)
return E_INVALIDARG;
if (ppResult == nullptr)
return E_INVALIDARG;
DxcThreadMalloc TM(m_pMalloc);

try {
// Allocate memory for new dxil container.
uint32_t ContainerSize = ComputeContainerSize();
Expand Down Expand Up @@ -161,6 +164,13 @@ DxcContainerBuilder::SerializeContainer(IDxcOperationResult **ppResult) {
errorHeap.Detach();
}

// Add Hash.
LPVOID PTR = pResult->GetBufferPointer();
if (!IsDxilContainerLike(PTR, pResult->GetBufferSize()))
return E_FAIL;

HashAndUpdate((DxilContainerHeader *)PTR);
Comment on lines +168 to +172
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, IsDxilContainerLike should never fail here, and it returns the DxilContainerHeader * upon success. Plus, we need to make sure validation succeeded before hashing:

Suggested change
LPVOID PTR = pResult->GetBufferPointer();
if (!IsDxilContainerLike(PTR, pResult->GetBufferSize()))
return E_FAIL;
HashAndUpdate((DxilContainerHeader *)PTR);
if (SUCCEEDED(valHR))
HashAndUpdate(IsDxilContainerLike(pResult->GetBufferPointer(),
pResult->GetBufferSize()));


IFT(DxcResult::Create(
valHR, DXC_OUT_OBJECT,
{DxcOutputObject::DataOutput(DXC_OUT_OBJECT, pResult, DxcOutNoName),
Expand All @@ -169,21 +179,6 @@ DxcContainerBuilder::SerializeContainer(IDxcOperationResult **ppResult) {
}
CATCH_CPP_RETURN_HRESULT();

if (ppResult == nullptr || *ppResult == nullptr)
return S_OK;

HRESULT HR;
(*ppResult)->GetStatus(&HR);
if (FAILED(HR))
return HR;

CComPtr<IDxcBlob> pObject;
IFR((*ppResult)->GetResult(&pObject));

// Add Hash.
LPVOID PTR = pObject->GetBufferPointer();
if (IsDxilContainerLike(PTR, pObject->GetBufferSize()))
HashAndUpdate((DxilContainerHeader *)PTR);
return S_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/clang/tools/dxclib/dxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ int DxcContext::VerifyRootSignature() {
IFT(pContainerBuilder->AddPart(hlsl::DxilFourCC::DFCC_RootSignature,
pRootSignature));
CComPtr<IDxcOperationResult> pOperationResult;
pContainerBuilder->SerializeContainer(&pOperationResult);
IFT(pContainerBuilder->SerializeContainer(&pOperationResult));
HRESULT status = E_FAIL;
CComPtr<IDxcBlob> pResult;
IFT(pOperationResult->GetStatus(&status));
Expand Down
Loading