Decide whether pe_map_release should reject a pointer pe_map_image did not return #164
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#164
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@raulmoracode on GitHub · 2026-11-21 17:50 UTC · original
Question
Should
pe_map_releasereject a pointer thatpe_map_imagedid not return, and should a second release of the same image be rejected instead of reachingVirtualFree?Today
pe_map_releasedereferences DOS and NT headers directly from the argument and then callsVirtualFreeon it. There is no registry of live images, no ownership tag and no double-release guard. The header read is only valid for a base returned bype_map_image, which is stated in a comment but not enforced.Evidence so far
tools/pe_map.cpp,pe_map_release:Image{base, 0}.headers()readse_lfanewfrom the argument before any check, then readsOptionalHeader.SizeOfImageand the TLS and.pdatadirectories.pe_map_imageallocates withVirtualAlloc(nullptr, SizeOfImage, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)and returns the base without recording it anywhere.docs/experiments.mddescribes the mapped-image lifecycle for callbacks but does not state what happens for a pointer the mapper did not return.Two possible directions
pe_map_releasereturns early (or sets a named status) when the pointer is not in the set, and removes it on success. This makes double release and foreign pointers safe and testable, at the cost of shared state.pe_map_imageand only guard against an uncommitted or non-image page withVirtualQuery, without tracking ownership. Cheaper, but a double release can still reachVirtualFree.Either way the behaviour needs to be written down before a test asserts it.
Completion condition
A maintainer picks one direction, and a source-built test proves the chosen behaviour:
.pdatatable.Required environment
x64 Windows, MSVC, CMake/Ninja, Python 3.11 or newer with
pefile. No game files.AI-assisted.
@R0Y00 on GitHub · 2026-11-21 18:08 UTC · original
Decision requested from the lead developer. Should callers be required to pass a currently live base returned by
pe_map_imageexactly once, or should the API guarantee a defined result for foreign and already-released pointers? Please specify the observable result, the existing null behavior and what callers can rely on if the same address is reused. This determines the ownership tracking and the regression tests. Leaving this issue open pending that decision.@R0Y00 on GitHub · 2026-11-21 18:09 UTC · original
Related implementation: #139 at
d18809a5changespe_map_releasefromvoidtoint, returns 0 when the address is absent from its live-image registry, and can defer process detach and unmapping until the final notification reference drops. Please decide the return contract and whether successful release can return before detach finishes. The earlier rebase and lifetime test requests on #139 have been addressed.@R0Y00 on GitHub · 2026-11-21 19:05 UTC · original
Decision recorded: use the live-base registry. A successful release returns 1 upon unregistering. Unrecognized bases return 0 without being dereferenced. The final in-flight notification owns deferred cleanup. This issue stays open for the implementation and Windows lifetime/TLS/SEH evidence in #139. Full contract and acceptance criteria
@R0Y00 on GitHub · 2026-11-21 20:26 UTC · original
Implemented in #139 (
da2bdd12). The Windows lifetime fixture covers foreign, interior and repeated releases, one winner on concurrent release, and unwind-table removal after the last in-flight notification.