From 0498415f1d6ac0bfbda72486505c11a7b3d464c4 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Mon, 6 Jun 2022 11:16:16 -0500 Subject: [PATCH] Fix overflow bug impacting 32-bit testing This test was failing on 32-bit arm builders due to an interger overflow. This changes the math to avoid overflow and should resolve the test failure. --- llvm/lib/Object/DXContainer.cpp | 7 ++++++- llvm/unittests/Object/DXContainerTest.cpp | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp index ae3d2f0..9fda608 100644 --- a/llvm/lib/Object/DXContainer.cpp +++ b/llvm/lib/Object/DXContainer.cpp @@ -60,7 +60,12 @@ Error DXContainer::parsePartOffsets() { if (Error Err = readInteger(Data.getBuffer(), Current, PartOffset)) return Err; Current += sizeof(uint32_t); - if (PartOffset + sizeof(dxbc::PartHeader) > Data.getBufferSize()) + // We need to ensure that each part offset leaves enough space for a part + // header. To prevent overflow, we subtract the part header size from the + // buffer size, rather than adding to the offset. Since the file header is + // larger than the part header we can't reach this code unless the buffer + // is larger than the part header, so this can't underflow. + if (PartOffset > Data.getBufferSize() - sizeof(dxbc::PartHeader)) return parseFailed("Part offset points beyond boundary of the file"); PartOffsets.push_back(PartOffset); } diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp index 084b727..14fb4b8 100644 --- a/llvm/unittests/Object/DXContainerTest.cpp +++ b/llvm/unittests/Object/DXContainerTest.cpp @@ -70,11 +70,7 @@ TEST(DXCFile, ParsePartMissingOffsets) { FailedWithMessage("Reading structure out of file bounds")); } -#if defined(__arm__) -TEST(DXCFile, DISABLED_ParsePartInvalidOffsets) { -#else TEST(DXCFile, ParsePartInvalidOffsets) { -#endif uint8_t Buffer[] = { 0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, -- 2.7.4