mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GT-3433: Fixed exception in PeLoader that occurred when creating a
memory block for a section when the section size exceeded the file size (fixes #1371)
This commit is contained in:
parent
21d9b041ac
commit
f103e1c334
1 changed files with 5 additions and 2 deletions
|
@ -24,7 +24,6 @@ import ghidra.app.util.bin.format.FactoryBundledWithBinaryReader;
|
|||
import ghidra.app.util.bin.format.pe.debug.DebugCOFFSymbol;
|
||||
import ghidra.app.util.bin.format.pe.debug.DebugCOFFSymbolAux;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.program.model.mem.MemoryAccessException;
|
||||
import ghidra.program.model.mem.MemoryBlock;
|
||||
import ghidra.util.DataConverter;
|
||||
import ghidra.util.Msg;
|
||||
|
@ -313,13 +312,17 @@ public class FileHeader implements StructConverter {
|
|||
for (int i = 0; i < numberOfSections; ++i) {
|
||||
sectionHeaders[i] = SectionHeader.createSectionHeader(reader, tmpIndex);
|
||||
|
||||
// Ensure PointerToRawData + SizeOfRawData doesn't exceed the length of the file
|
||||
int pointerToRawData = sectionHeaders[i].getPointerToRawData();
|
||||
int sizeOfRawData = (int) Math.min(reader.length() - pointerToRawData,
|
||||
sectionHeaders[i].getSizeOfRawData());
|
||||
|
||||
// Ensure VirtualSize is large enough to accommodate SizeOfRawData, but do not
|
||||
// exceed the next alignment boundary. We can only do this if the VirtualAddress is
|
||||
// already properly aligned, since we currently don't support moving sections to
|
||||
// different addresses to enforce alignment.
|
||||
int virtualAddress = sectionHeaders[i].getVirtualAddress();
|
||||
int virtualSize = sectionHeaders[i].getVirtualSize();
|
||||
int sizeOfRawData = sectionHeaders[i].getSizeOfRawData();
|
||||
int alignedVirtualAddress = PortableExecutable.computeAlignment(virtualAddress,
|
||||
optHeader.getSectionAlignment());
|
||||
int alignedVirtualSize = PortableExecutable.computeAlignment(virtualSize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue