[llvm] b953914 - [Object][COFF] Fix CHPE metadata offset check (#109591)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 01:46:41 PDT 2024


Author: Jacek Caban
Date: 2024-09-23T10:46:37+02:00
New Revision: b953914e2fef53773baa1fa89e96671015d45852

URL: https://github.com/llvm/llvm-project/commit/b953914e2fef53773baa1fa89e96671015d45852
DIFF: https://github.com/llvm/llvm-project/commit/b953914e2fef53773baa1fa89e96671015d45852.diff

LOG: [Object][COFF] Fix CHPE metadata offset check (#109591)

Added: 
    

Modified: 
    llvm/lib/Object/COFFObjectFile.cpp
    llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index 5fdf3baf8c02cc..3ec7a449bae798 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -763,7 +763,7 @@ Error COFFObjectFile::initLoadConfigPtr() {
       if (Error E =
               getRvaPtr(ChpeOff - getImageBase(), IntPtr, "CHPE metadata"))
         return E;
-      if (Error E = checkOffset(Data, IntPtr, sizeof(CHPEMetadata)))
+      if (Error E = checkOffset(Data, IntPtr, sizeof(*CHPEMetadata)))
         return E;
 
       CHPEMetadata = reinterpret_cast<const chpe_metadata *>(IntPtr);

diff  --git a/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml b/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
index 1f5e7e10888989..91dde600d83748 100644
--- a/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
+++ b/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
@@ -150,3 +150,34 @@ sections:
       - UInt32: 4       # HybridImageInfoBitfield
 symbols:         []
 ...
+
+# RUN: yaml2obj --docnum=3 %s -o %t3
+# RUN: not llvm-readobj --coff-load-config %t3 2>&1 | FileCheck --check-prefix=ERR-EOF %s
+# ERR-EOF: The end of the file was unexpectedly encountered
+
+--- !COFF
+OptionalHeader:
+  ImageBase:       0x180000000
+  SectionAlignment: 4096
+  FileAlignment:   512
+  DLLCharacteristics: [ ]
+  LoadConfigTable:
+    RelativeVirtualAddress: 0x4000
+    Size:            320
+header:
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE, IMAGE_FILE_DLL ]
+sections:
+  - Name:            .text
+    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+    VirtualAddress:  0x1000
+    VirtualSize:     0x2050
+  - Name:            .rdata
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+    VirtualAddress:  0x4000
+    VirtualSize:     512
+    StructuredData:
+      - LoadConfig:
+          CHPEMetadataPointer: 0x1800041AC
+symbols:         []
+...


        


More information about the llvm-commits mailing list