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

Conversation

batuzovk
Copy link
Contributor

Debug directory is not necessary for program execution. Sometimes toolchains put there data not conforming to any standards. It is still possible to parse the rest of the file, no need to fail parsing with an error.

@batuzovk batuzovk requested a review from woodruffw as a code owner February 14, 2024 10:42
@CLAassistant
Copy link

CLAassistant commented Feb 14, 2024

CLA assistant check
All committers have signed the CLA.

@batuzovk
Copy link
Contributor Author

batuzovk commented Apr 1, 2024

@woodruffw , may I ask to review and hopefully merge this change? It is a simple change, but it allows parsing of some files on which pe-parse fails currently.

@woodruffw
Copy link
Member

I'll try to set aside some time for a review in the coming days.

@woodruffw woodruffw self-assigned this Apr 1, 2024
@batuzovk
Copy link
Contributor Author

batuzovk commented Jun 7, 2024

I believe this change is straightforward, but if there are any concerns that prevent merging it, I would be glad to address them.

@woodruffw
Copy link
Member

Sorry for the delay @batuzovk -- this change is indeed straightforward, but I need to do a more in-depth read to make sure it doesn't break any of our larger invariants about expecting sections to be present: this codebase hasn't seen active development in a while, so I'll need to refamiliarize myself before I'm comfortable merging this 🙂

(Specifically, my concern is that there may be places where parsed_pe_internals.debugdirs is assumed to be nonempty. I don't think that's the case, but I'll need to manually confirm that.)

@woodruffw
Copy link
Member

Actually, looks like I was wrong about the above: it should be safe to never populate debugdirs, since all uses iterate over it and have sensible behavior when it's empty (e.g. not firing an invalid callback).

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One request for comments, otherwise LGTM! Sorry for the delay here @batuzovk, and thank you.

Comment on lines 1884 to 1907
return false;
break;
}

//
// Get the section for the data
//
section dataSec;
if (!getSecForVA(p->internal->secs, rawData, dataSec)) {
return false;
break;
}

debugent ent;

auto dataofft = static_cast<std::uint32_t>(rawData - dataSec.sectionBase);
if (dataofft + curEnt.SizeOfData > dataSec.sectionData->bufLen) {
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick: I'd be good to have comments on these breaks explaining that we silently ignore invalid Debug Directory entries, rather than failing on them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added comments and update the code in the review.

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @batuzovk!

@woodruffw
Copy link
Member

BTW, do you happen to have an example of a PE with a malformed debug entry? It'd be useful to have a backstop/regression test here. Nonblocker, however.

@batuzovk
Copy link
Contributor Author

batuzovk commented Jun 7, 2024

There is an example of a file with a malformed debug entry in issue #190 When dump-pe is run on System.Text.Json.dll from the attached archive, it fails without this change, but prints information correctly with it.

I see some CI checks failing. Some aren't related to my changes, but lint seem to be unhappy about the length of comment lines. Should I reformat those or will CI do it itself?

@woodruffw
Copy link
Member

I see some CI checks failing. Some aren't related to my changes, but lint seem to be unhappy about the length of comment lines. Should I reformat those or will CI do it itself?

Yeah, if you could reformat, that would be great.

(Don't worry about the unrelated failures -- that's a known deprecation thing. I'll merge regardless of those, and fix the build with a follow-up.)

Debug directory is not necessary for program execution. Sometimes toolchains
put there data not conforming to any standards. It is still possible to
parse the rest of the file, no need to fail parsing with an error.
@batuzovk
Copy link
Contributor Author

batuzovk commented Jun 7, 2024

Comment formatting was updated. Also, rebased on new master (no changes, clean rebase).

@woodruffw woodruffw merged commit f2f0ee9 into trailofbits:master Jun 7, 2024
22 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants