[PATCH] D37044: Fix bug 34051 by handling empty .res files gracefully.
Eric Beckmann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 22 17:39:40 PDT 2017
ecbeckmann created this revision.
Herald added a subscriber: hiraditya.
Previously, llvm-cvtres crashes on .res files which are empty except for
the null header. This allows the library to simply pass over them.
https://reviews.llvm.org/D37044
Files:
llvm/include/llvm/Object/WindowsResource.h
llvm/lib/Object/WindowsResource.cpp
Index: llvm/lib/Object/WindowsResource.cpp
===================================================================
--- llvm/lib/Object/WindowsResource.cpp
+++ llvm/lib/Object/WindowsResource.cpp
@@ -57,6 +57,11 @@
}
Expected<ResourceEntryRef> WindowsResource::getHeadEntry() {
+ if (BBS.getLength() <
+ sizeof(WinResHeaderPrefix) + sizeof(WinResHeaderSuffix)) {
+ return make_error<EmptyResError>(".res contains no entries",
+ object_error::unexpected_eof);
+ }
Error Err = Error::success();
auto Ref = ResourceEntryRef(BinaryStreamRef(BBS), this, Err);
if (Err)
@@ -67,9 +72,10 @@
ResourceEntryRef::ResourceEntryRef(BinaryStreamRef Ref,
const WindowsResource *Owner, Error &Err)
: Reader(Ref), OwningRes(Owner) {
- if (loadNext())
- Err = make_error<GenericBinaryError>("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 +133,14 @@
Error WindowsResourceParser::parse(WindowsResource *WR) {
auto EntryOrErr = WR->getHeadEntry();
- if (!EntryOrErr)
- return EntryOrErr.takeError();
+ if (!EntryOrErr) {
+ auto E = EntryOrErr.takeError();
+ if (E.isA<EmptyResError>()) {
+ consumeError(std::move(E));
+ return Error::success();
+ }
+ return E;
+ }
ResourceEntryRef Entry = EntryOrErr.get();
bool End = false;
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37044.112273.patch
Type: text/x-patch
Size: 2091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170823/3682c43f/attachment.bin>
More information about the llvm-commits
mailing list