Harden PE resource parser against malformed/truncated input and binary-field misreads - #6
Draft
sharkwouter with Copilot wants to merge 3 commits into
Draft
sharkwouter with Copilot wants to merge 3 commits into
sharkwouter with Copilot wants to merge 3 commits into
Conversation
Copilot
AI
changed the title
[WIP] Harden PE parser implementation by addressing unsafe patterns
Harden PE resource parser against malformed/truncated input and binary-field misreads
Jun 16, 2026
Owner
|
This is mostly a test to see how copilot works, before I use it to do more serious work. I know there are some code paths which could make pe-resource-loader do things it is not supposed to when a maliciously wrong/corrupted pe file is given to it. So this seemed like a good test to me. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR hardens
src/pe_resource_loader.cfor untrusted PE input by eliminating unchecked I/O/allocation paths and validating file-derived offsets/sizes before use. It also fixes binary-field comparison bugs (PE\0\0,.rsrcname) and closely related correctness/memory issues exposed by these changes.Parser I/O and allocation hardening
Binary field correctness (no string semantics on fixed-width data)
.rsrcsection-name string logic with exact 8-byte section-name matching.Offset/size validation and overflow guards
MAX_LANG_COUNToverrun.Unsafe stack allocation removal and related fixes
BMbyte check) and tightened bitmap/cursor/icon processing for invalid/short payloads.Targeted hardening coverage
tests/hardening_test.c) integrated with CMake/CTest to cover malformed/truncated open paths and bitmap edge behavior.