Skip to content
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

Stop at non-conforming Debug Directory entry #199

Merged
merged 1 commit into from
Jun 7, 2024
Merged
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
14 changes: 12 additions & 2 deletions pe-parser-library/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1881,20 +1881,30 @@ bool getDebugDir(parsed_pe *p) {
rawData =
curEnt.AddressOfRawData + p->peHeader.nt.OptionalHeader64.ImageBase;
} else {
return false;
// Unrecognized optional header type. We can't process debug entries.
// Debug entries themselves are optional, so skip them.
break;
}

//
// Get the section for the data
//
section dataSec;
if (!getSecForVA(p->internal->secs, rawData, dataSec)) {
return false;
// The debug entry points to non-existing data. This means it is
// malformed. Skip it and the rest. They are not necessary for parsing
// the binary, and binaries do have malformed debug entries sometimes.
break;
}

debugent ent;

auto dataofft = static_cast<std::uint32_t>(rawData - dataSec.sectionBase);
if (dataofft + curEnt.SizeOfData > dataSec.sectionData->bufLen) {
// The debug entry data stretches outside the containing section. It is
// malformed. Skip it and the rest, similar to the above.
break;
}
ent.type = curEnt.Type;
ent.data = makeBufferFromPointer(
reinterpret_cast<std::uint8_t *>(dataSec.sectionData->buf + dataofft),
Expand Down
Loading