Skip to content

[Object][COFF] Fix CHPE metadata offset check #109591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/Object/COFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
...
Loading