[PATCH] D32652: Gracefully handle empty .drectve sections

Dave Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 28 11:48:18 PDT 2017


kastiglione created this revision.

Running `llvm-readobj -coff-directives msvcrt.lib` resulted in this error:

  Invalid data was encountered while parsing the file

This happened because some of the object files in the archive have empty
`.drectve` sections. These empty sections result in a `parse_failed` error being
returned from `COFFObjectFile::getSectionContents()`, which in turn caused
`llvm-readobj` to stop. Checking the section size first allows `llvm-readobj` to
gracefully handle these empty directives.


https://reviews.llvm.org/D32652

Files:
  tools/llvm-readobj/COFFDumper.cpp


Index: tools/llvm-readobj/COFFDumper.cpp
===================================================================
--- tools/llvm-readobj/COFFDumper.cpp
+++ tools/llvm-readobj/COFFDumper.cpp
@@ -1487,7 +1487,7 @@
     StringRef Name;
 
     error(Section.getName(Name));
-    if (Name != ".drectve")
+    if (Name != ".drectve" || Section.getSize() == 0)
       continue;
 
     error(Section.getContents(Contents));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32652.97133.patch
Type: text/x-patch
Size: 411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170428/ca574867/attachment.bin>


More information about the llvm-commits mailing list