Skip to content

Commit 7e1a307

Browse files
committed
[LLDB] [PECOFF] Don't crash in ReadImageDataByRVA for addresses out of range
This can happen e.g. when unwinding doesn't work perfectly. Differential Revision: https://reviews.llvm.org/D69502
1 parent e65ddca commit 7e1a307

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,10 @@ DataExtractor ObjectFilePECOFF::ReadImageData(uint32_t offset, size_t size) {
564564
DataExtractor ObjectFilePECOFF::ReadImageDataByRVA(uint32_t rva, size_t size) {
565565
if (m_file) {
566566
Address addr = GetAddress(rva);
567-
rva = addr.GetSection()->GetFileOffset() + addr.GetOffset();
567+
SectionSP sect = addr.GetSection();
568+
if (!sect)
569+
return {};
570+
rva = sect->GetFileOffset() + addr.GetOffset();
568571
}
569572

570573
return ReadImageData(rva, size);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--- !minidump
2+
Streams:
3+
- Type: ModuleList
4+
Modules:
5+
- Base of Image: 0x00000000000B0000
6+
Size of Image: 0x00005000
7+
Module Name: 'find-module.exe'
8+
CodeView Record: 52534453E092B2141AD8F1B44C4C44205044422E01000000433A5C70726F6A656374735C746573745F6170705C436F6E736F6C654170706C69636174696F6E315C44656275675C436F6E736F6C654170706C69636174696F6E312E70646200
9+
- Type: SystemInfo
10+
Processor Arch: X86
11+
Processor Level: 23
12+
Processor Revision: 2050
13+
Number of Processors: 32
14+
Product type: 1
15+
Major Version: 10
16+
Build Number: 17134
17+
Platform ID: Win32NT
18+
Suite Mask: 0x0300
19+
CPU:
20+
Vendor ID: AuthenticAMD
21+
Version Info: 0x00800F82
22+
Feature Info: 0x178BFBFF
23+
AMD Extended Features: 0x2FD3FBFF
24+
- Type: MiscInfo
25+
Content: 54050000F703000008290000C883495D0000000000000000AC0D000098080000AC0D00000200000002000000002000000D0000000000000002000000C4FFFFFF430065006E007400720061006C0020004500750072006F007000650020005300740061006E0064006100720064002000540069006D006500000000000000000000000A0000000500030000000000000000000000430065006E007400720061006C0020004500750072006F00700065002000530075006D006D00650072002000540069006D00650000000000000000000000000000000300000005000200000000000000C4FFFFFF310037003100330034002E0031002E007800380036006600720065002E007200730034005F00720065006C0065006100730065002E003100380030003400310030002D00310038003000340000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064006200670063006F00720065002E0069003300380036002C00310030002E0030002E00310037003100330034002E0031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006C816B92
26+
- Type: ThreadList
27+
Threads:
28+
- Thread Id: 0x0000290C
29+
Priority Class: 0x00000020
30+
Environment Block: 0x0000000000A98000
31+
Context: 3F0001000000000000000000000000000000000000000000000000007F02000000000000FFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002B000000530000002B0000002B00000080100B0080100B000050A90080100B0080100B0000000000E4FECF0092100B0023000000440301007CFECF002B0000007F0200000000000000000000000000000000000000000000801F0000FFFF020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000144E3D6C2000000001000000EA1E00F4C000E50700000000FC0100002CE3C014D8E202010000E507880F401D839DC60100000000400000007F00000000000000880F401D0A000000900F401D0000000000000100EA1E00009808E5077F00000000000000000000009008E507990100006002E5072CABC87708346474B42300000100000044E3C014200000000000000020532777A80F401D4F346474D00F401D6F378CCC5C4CD5010000000000000000000000000000000000000000000000003AFCD72F90E3C01418CE3470B4230000B80F401DC00F401DC80F401DD00F401D
32+
Stack:
33+
Start of Memory Range: 0x0000000000CFFE78
34+
Content: 0000000079100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0000100B0085100B0094842777
35+
...
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# The ExceptionTable RelativeVirtualAddress below points outside of allocated
2+
# sections.
3+
4+
--- !COFF
5+
OptionalHeader:
6+
AddressOfEntryPoint: 4224
7+
ImageBase: 4194304
8+
SectionAlignment: 4096
9+
FileAlignment: 512
10+
MajorOperatingSystemVersion: 6
11+
MinorOperatingSystemVersion: 0
12+
MajorImageVersion: 0
13+
MinorImageVersion: 0
14+
MajorSubsystemVersion: 6
15+
MinorSubsystemVersion: 0
16+
Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
17+
DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT, IMAGE_DLL_CHARACTERISTICS_NO_SEH, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE ]
18+
SizeOfStackReserve: 1048576
19+
SizeOfStackCommit: 4096
20+
SizeOfHeapReserve: 1048576
21+
SizeOfHeapCommit: 4096
22+
ExportTable:
23+
RelativeVirtualAddress: 8327
24+
Size: 90
25+
ImportTable:
26+
RelativeVirtualAddress: 0
27+
Size: 0
28+
ResourceTable:
29+
RelativeVirtualAddress: 0
30+
Size: 0
31+
ExceptionTable:
32+
RelativeVirtualAddress: 12303
33+
Size: 12
34+
CertificateTable:
35+
RelativeVirtualAddress: 0
36+
Size: 0
37+
BaseRelocationTable:
38+
RelativeVirtualAddress: 0
39+
Size: 0
40+
Debug:
41+
RelativeVirtualAddress: 8192
42+
Size: 28
43+
Architecture:
44+
RelativeVirtualAddress: 0
45+
Size: 0
46+
GlobalPtr:
47+
RelativeVirtualAddress: 0
48+
Size: 0
49+
TlsTable:
50+
RelativeVirtualAddress: 0
51+
Size: 0
52+
LoadConfigTable:
53+
RelativeVirtualAddress: 0
54+
Size: 0
55+
BoundImport:
56+
RelativeVirtualAddress: 0
57+
Size: 0
58+
IAT:
59+
RelativeVirtualAddress: 0
60+
Size: 0
61+
DelayImportDescriptor:
62+
RelativeVirtualAddress: 0
63+
Size: 0
64+
ClrRuntimeHeader:
65+
RelativeVirtualAddress: 0
66+
Size: 0
67+
header:
68+
Machine: IMAGE_FILE_MACHINE_I386
69+
Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_32BIT_MACHINE ]
70+
sections:
71+
- Name: .text
72+
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
73+
VirtualAddress: 4096
74+
VirtualSize: 22
75+
SectionData: 50894C24048B4C24040FAF4C2404890C248B042459C3
76+
- Name: .rdata
77+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
78+
VirtualAddress: 8192
79+
VirtualSize: 236
80+
SectionData: 00000000A565B65C00000000020000006B0000001C2000001C06000052534453E092B2141AD8F1B44C4C44205044422E01000000443A5C757073747265616D5C6275696C645C746F6F6C735C6C6C64625C6C69745C4D6F64756C65735C5045434F46465C4F75747075745C6578706F72742D646C6C66756E632E79616D6C2E746D702E70646200000000000000000000000000AF200000000000000200000001000000CB200000D3200000D72000006578706F72742D646C6C66756E632E79616D6C2E746D702E646C6C000000000000100000D92000000100446C6C46756E63000000000101010001020000
81+
- Name: .pdata
82+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
83+
VirtualAddress: 12288
84+
VirtualSize: 12
85+
SectionData: '0010000016100000E4200000'
86+
symbols: []
87+
...
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Test that we can cope with broken unwind information that suggests
2+
reading out of bounds.
3+
4+
RUN: yaml2obj %S/Inputs/broken-unwind.exe.yaml > %T/broken-unwind.exe
5+
RUN: yaml2obj %S/Inputs/broken-unwind.dmp.yaml > %T/broken-unwind.dmp
6+
RUN: %lldb -O "settings set target.exec-search-paths %T" \
7+
RUN: -c %T/broken-unwind.dmp -o "image show-unwind -a 0xb1000" -o exit

0 commit comments

Comments
 (0)