Python: fix heap-use-after-free in MapIterator after map.clear()#27257
Python: fix heap-use-after-free in MapIterator after map.clear()#27257vhullto wants to merge 8 commits into
Conversation
|
@JasonLunn could you re-apply the |
|
This PR fixes a heap-use-after-free reported to Google OSS VRP (Issue 514465085). The VRP team is waiting for the merge to process the report. Could a maintainer review this? |
|
Note: this PR also fixes the heap-use-after-free reported to Google OSS VRP (issue #510416822). |
|
@anandolee could you take a look when you have a moment? All checks are passing. Thank you! |
|
@JasonLunn @rgoldfinger6 Could one of you review this when you have a moment? All 199 checks are passing and the fix is a single line (self->version++ in Clear()). Thank you! |
tonyliaoss
left a comment
There was a problem hiding this comment.
Thanks! This seems like a reasonable change.
|
@tonyliaoss Could you re-apply the |
|
@tonyliaoss The feedback/copybara check is failing on Google's internal side (the import/copybara import succeeded and the change merges cleanly). Could you take a look when you have a moment? The failure appears unrelated to this one-line change (self->version++ in Clear()). Thank you! |
|
Yes, I see the corresponding CL internally is approved. I'm not sure why Copybara hasn't merged this change in yet, but for now there is no action needed on your side. Thanks! |
|
This fix has been verified as merged via commit 9e9dbae (landed through Google's Copybara workflow). This PR resolves the heap-use-after-free reported to Google OSS VRP as Issue 514465085. The root cause — The regression test added in |
Bug
Clear()inmap_container.cc(line 294-302) callsreflection->ClearField()which destroys all underlying map nodes viaClearTable(reset=true), but does not incrementself->version.All other mutators (ScalarMapSetItem, MessageMapSetItem, MergeFrom, etc.)
increment
self->versionafter mutation.IterNext()relies on versionmismatch to detect concurrent modification and raise
RuntimeError.Without the version bump, a live iterator proceeds to dereference the
freed
NodeBase*viaSetMapIteratorValue→UntypedMapIterator::PlusPlus.ASAN confirmed: heap-use-after-free, READ size 8 at
UntypedMapIterator::PlusPlus(map.h:599), freed byClearTable(map.h:345), allocated by
ScalarMapSetItem(map_container.cc:416).Fix
Add
self->version++afterClearFieldinClear(), matching everyother mutator in the same file.
Reproducer