From 323f62d3d0f4b73db5fde8977e2540194c6de006 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 2 Nov 2021 17:47:46 -0500 Subject: Follow up for multiple attached container support * validate cContainers * use previous embeddedid format and use intermediate folder when extracting attached containers * remove special cases for 0 byte containers in BurnCommon classes and Insignia * don't hardcode max containers * reduce properties in BurnCommon * add e2e test #6144 --- src/burn/engine/section.cpp | 24 +++++++++++++----------- src/burn/stub/StubSection.cpp | 3 ++- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/burn') diff --git a/src/burn/engine/section.cpp b/src/burn/engine/section.cpp index 1fd6cce4..a9c7927e 100644 --- a/src/burn/engine/section.cpp +++ b/src/burn/engine/section.cpp @@ -26,7 +26,7 @@ typedef struct _BURN_SECTION_HEADER DWORD dwFormat; DWORD cContainers; - DWORD rgcbContainers[116]; + DWORD rgcbContainers[1]; } BURN_SECTION_HEADER; static HRESULT VerifySectionMatchesMemoryPEHeader( @@ -53,6 +53,7 @@ extern "C" HRESULT SectionInitialize( IMAGE_SECTION_HEADER sectionHeader = { }; DWORD_PTR dwOriginalChecksumAndSignatureOffset = 0; BURN_SECTION_HEADER* pBurnSectionHeader = NULL; + DWORD cMaxContainers = 0; pSection->hEngineFile = hEngineFile; ExitOnInvalidHandleWithLastError(pSection->hEngineFile, hr, "Failed to open handle to engine process path."); @@ -142,8 +143,7 @@ extern "C" HRESULT SectionInitialize( } if (sizeof(IMAGE_SECTION_HEADER) > cbRead) { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - ExitOnRootFailure(hr, "Failed to read complete image section header, index: %u", i); + ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read complete image section header, index: %u", i); } // compare header name @@ -156,8 +156,7 @@ extern "C" HRESULT SectionInitialize( // fail if we hit the end if (i + 1 >= ntHeader.FileHeader.NumberOfSections) { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - ExitOnRootFailure(hr, "Failed to find Burn section."); + ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to find Burn section."); } } @@ -168,8 +167,7 @@ extern "C" HRESULT SectionInitialize( // check size of section if (sizeof(BURN_SECTION_HEADER) > sectionHeader.SizeOfRawData) { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - ExitOnRootFailure(hr, "Failed to read section info, data to short: %u", sectionHeader.SizeOfRawData); + ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read section info, data too short: %u", sectionHeader.SizeOfRawData); } // allocate buffer for section info @@ -193,15 +191,19 @@ extern "C" HRESULT SectionInitialize( } else if (sectionHeader.SizeOfRawData > cbRead) { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - ExitOnRootFailure(hr, "Failed to read complete section info."); + ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read complete section info."); } // validate version of section info if (BURN_SECTION_VERSION != pBurnSectionHeader->dwVersion) { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - ExitOnRootFailure(hr, "Failed to read section info, unsupported version: %08x", pBurnSectionHeader->dwVersion); + ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read section info, unsupported version: %08x", pBurnSectionHeader->dwVersion); + } + + cMaxContainers = (sectionHeader.SizeOfRawData - offsetof(BURN_SECTION_HEADER, rgcbContainers)) / sizeof(DWORD); + if (cMaxContainers < pBurnSectionHeader->cContainers) + { + ExitWithRootFailure(hr, E_INVALIDDATA, "Invalid section info, cContainers too large: %u", pBurnSectionHeader->cContainers); } hr = FileSizeByHandle(pSection->hSourceEngineFile, &llSize); diff --git a/src/burn/stub/StubSection.cpp b/src/burn/stub/StubSection.cpp index 01b4b576..2191a138 100644 --- a/src/burn/stub/StubSection.cpp +++ b/src/burn/stub/StubSection.cpp @@ -18,5 +18,6 @@ static DWORD dwOriginalSignatureSize = 0; static DWORD dwContainerFormat = 1; static DWORD dwContainerCount = 0; -static DWORD qwAttachedContainerSizes[116]; // Including UX container +// (512 (minimum section size) - 48 (size of above data)) / 4 (size of DWORD) +static DWORD qwAttachedContainerSizes[116]; #pragma data_seg(pop) -- cgit v1.2.3-55-g6feb