'fix: prevent undefined behavior in unpin_slot when slot is not pinned' #3309
No reviewers
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!3309
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3307"
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?
@KelboLive on GitHub · 2026-11-28 07:25 UTC · original
KelboLive:fix/xmem-unpin-slot-crash-final→main· +1 −0 · 1 files · 1 commits · merged 2026-11-28 08:24 UTCSummary
Fixed a critical bug in
src/xmem_mapped_pages.cppwhere theunpin_slotfunction dereferenced the result ofmemory.pins.find(slot)without checking if it equalsend(). If called with a slot not present inpins, this causes undefined behavior/crash.Changes
if (found == memory.pins.end()) return;) before dereferencing the iterator inunpin_slot.Testing
@JohnConnorNPC on GitHub · 2026-11-28 08:00 UTC · original
Thanks for this. I reviewed head
ca165ed9by reading it (static review, no build, no Wine, no GPU). It adds one line (git diff --numstatgives1 0 src/xmem_mapped_pages.cpp) and merges cleanly intomainc3204a9c(git merge-tree --write-treerc=0). I found nothing blocking. The guard is harmless, but as far as I can tell no current caller can reach it.git grep -n 'memory\.pins' -- srcfinds one insert,++memory.pins[slot].references;inx2w_xmem_lease_section, and one erase, inunpin_slotonce the count reaches 0.unpin_slothas two callers (git grep -n 'unpin_slot(' -- src). Thebad_allocpath unpins onlyselected[i]fori < pinned, which are the slots it already incremented.x2w_xmem_release_sectionunpins each slot of a lease once and then erases the lease, so a second release fails the lease lookup first. Sofinddoesn't returnend()today.ctest --preset pr:100% tests passed out of 73). The /O2 job onmainatc3204a9c, which is this PR minus the new line, passed all fivexmem_section_lease_checktests (#66–#70), including the double-release control "retire pin once". So no test fails without the guard.Suggestions (none blocking):
returnwould also hide a refcount desync introduced by some future change, and whether to fail fast there instead is the maintainer's call. No issue is linked.This comment was AI-assisted.