Index: llvm/include/llvm/Object/WindowsResource.h =================================================================== --- llvm/include/llvm/Object/WindowsResource.h +++ llvm/include/llvm/Object/WindowsResource.h @@ -85,6 +85,13 @@ support::ulittle32_t Characteristics; }; +class EmptyResError : public GenericBinaryError { +public: + EmptyResError(Twine Msg, object_error ECOverride) + : GenericBinaryError(Msg, ECOverride) {} + static char ID; +}; + class ResourceEntryRef { public: Error moveNext(bool &End); Index: llvm/lib/Object/WindowsResource.cpp =================================================================== --- llvm/lib/Object/WindowsResource.cpp +++ llvm/lib/Object/WindowsResource.cpp @@ -57,6 +57,9 @@ } Expected WindowsResource::getHeadEntry() { + if (BBS.getLength() < sizeof(WinResHeaderPrefix) + sizeof(WinResHeaderSuffix)) + return make_error(".res contains no entries", + object_error::unexpected_eof); Error Err = Error::success(); auto Ref = ResourceEntryRef(BinaryStreamRef(BBS), this, Err); if (Err) @@ -67,9 +70,10 @@ ResourceEntryRef::ResourceEntryRef(BinaryStreamRef Ref, const WindowsResource *Owner, Error &Err) : Reader(Ref), OwningRes(Owner) { - if (loadNext()) - Err = make_error("Could not read first entry.\n", - object_error::unexpected_eof); + if (auto E = loadNext()) { + consumeError(std::move(Err)); + Err = std::move(E); + } } Error ResourceEntryRef::moveNext(bool &End) { @@ -127,8 +131,14 @@ Error WindowsResourceParser::parse(WindowsResource *WR) { auto EntryOrErr = WR->getHeadEntry(); - if (!EntryOrErr) - return EntryOrErr.takeError(); + if (!EntryOrErr) { + auto E = EntryOrErr.takeError(); + if (E.isA()) { + consumeError(std::move(E)); + return Error::success(); + } + return E; + } ResourceEntryRef Entry = EntryOrErr.get(); bool End = false;