[lld] [LLD][COFF] Add support for IMPORT_NAME_EXPORTAS import library names. (PR #83211)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 12:08:10 PST 2024


================
@@ -944,18 +944,20 @@ ImportFile::ImportFile(COFFLinkerContext &ctx, MemoryBufferRef m)
     : InputFile(ctx, ImportKind, m), live(!ctx.config.doGC), thunkLive(live) {}
 
 void ImportFile::parse() {
-  const char *buf = mb.getBufferStart();
-  const auto *hdr = reinterpret_cast<const coff_import_header *>(buf);
+  const auto *hdr =
+      reinterpret_cast<const coff_import_header *>(mb.getBufferStart());
 
   // Check if the total size is valid.
-  if (mb.getBufferSize() != sizeof(*hdr) + hdr->SizeOfData)
+  if (mb.getBufferSize() < sizeof(*hdr) ||
+      mb.getBufferSize() != sizeof(*hdr) + hdr->SizeOfData)
----------------
cjacek wrote:

It's meant to check if we have enough data to read the header. As far as I can see we never verify that data size is large enough to fit `coff_import_header`, so reading `SizeOfData` may be accessing invalid memory.

https://github.com/llvm/llvm-project/pull/83211


More information about the llvm-commits mailing list