Repository navigation
[BUGFIX] Imports: bound the number of parsed functions - #34
Merged
hasherezade merged 1 commit intoNov 3, 2026
Merged
Conversation
Every import descriptor walks its thunk array until a zero thunk, with no limit (LIMIT = -1 in ImportBaseEntryWrapper::wrap). Nothing stops N descriptors from pointing to the same array of M thunks, so a file of size S can produce about (S/20) * (S/4) function wrappers. A file with 400 descriptors sharing one array of 10000 thunks (48 KB) gives no result within 30 s and 409 MB of resident memory when stopped; with this change it is parsed in 0.25 s and 13 MB. One budget now covers all the functions of a directory: getRawSize() divided by the thunk size (4 or 8). Every imported function of a well-formed file has its own thunk in the file, so the number of functions cannot exceed the number of thunks that fit in it. Each library gets what is left of the budget, a warning is logged when it runs out, and rewrapping a single entry does not count its functions twice. The code is in ImportBaseDirWrapper, so the delay-load directory uses it as well. Behaviour change: when several libraries share a thunk array, the functions beyond the budget are not listed.
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.
Every import descriptor walks its thunk array until a zero thunk, with no limit (
LIMIT = -1inImportBaseEntryWrapper::wrap). Nothing stops N descriptors from pointing to the same array of M thunks, so a file of size S can produce about (S/20) × (S/4) function wrappers. Same class of problem as hasherezade/pe-bear#77, in the imports instead of the resources; independent of #33.Change
One budget covers all the functions of a directory:
getRawSize()divided by the thunk size (4 or 8). Every imported function of a well-formed file has its own thunk in the file, so the number of functions cannot exceed the number of thunks that fit in it. Each library gets what is left of the budget, a warning is logged when it runs out, and rewrapping one entry does not count its functions twice. The code is inImportBaseDirWrapper, so the delay-load directory uses it too.Behaviour change: when several libraries share a thunk array, the functions beyond the budget are not listed.
Verification
Release build with gcc on
master. Input: a synthetic PE32 with 400 import descriptors that all point to one array of 10000 thunks (48 KB).bearcommander <file>with theimplistcommand, 30 s limit:masterA smaller file (40 descriptors × 100 thunks, 2 KB) lists 4000 functions on
masterand 512 with this change, which is the behaviour change above.test.shagainstbearparser_tests: 26 cases print OK with and without the change.x86/kernel32 : explistprints "Failed" on unmodifiedmastertoo.Not measured: the delay-load directory. It shares the code path but I did not build an input for it.