Index: lib/Object/COFFObjectFile.cpp =================================================================== --- lib/Object/COFFObjectFile.cpp +++ lib/Object/COFFObjectFile.cpp @@ -829,11 +829,21 @@ // within the file bounds. We don't need to make sure it doesn't cover other // data, as there's nothing that says that is not allowed. uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData; - uintptr_t ConEnd = ConStart + Sec->SizeOfRawData; + // COFF requires sections to follow certain alignment rules in PE + // files. Thus (in a PE file) a section's actual data may be smaller + // than SizeOfRawData. + // Since for debug sections later on the actual data matters, we take + // the min of SizeOfRawData and VirtualSize which is the acutal size + // of the data. + uintptr_t Size = Sec->SizeOfRawData; + // COFF Object files always have VirtualSize set to 0 + if (Sec->VirtualSize != 0) + Size = std::min(Size,(uintptr_t)Sec->VirtualSize); + uintptr_t ConEnd = ConStart + Size; if (ConEnd > uintptr_t(Data->getBufferEnd())) return object_error::parse_failed; Res = ArrayRef(reinterpret_cast(ConStart), - Sec->SizeOfRawData); + Size); return object_error::success; }