You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python bindings: fix use-after-free on sub-geometries of a feature's geometry - #15355
Each geometry a feature hands out now keep a weak reference to that feature. When you get a sub-geometry from it, the sub-geometry registered with the same feature. When the feature dies, all of them are invalidated together. Result with an exception instead of a crash, like GetGeometryRef() case.
What are related issues/pull requests?
AI tool usage
AI (Y-a-t-il-un-Copilot-dans-l'avion, Chat-j'ai-pété, Jean-Claude Dusse or something similar) supported my development of this PR. See our policy about AI tool use. Use of AI tools must be indicated.
A Geometry is not necessarily owned by any feature. Maybe better to have Geometry.__del__ invalidate any references it has handed out, the same way that Feature does?
For example, the following still segfaults with this PR:
Good point, thanks!
I'll switch to your approach: Geometry will track the sub-geometries it hands out, Destroy() will invalidate them, and the feature's invalidation will cascade down through them. This also drops the _owner_feature weakref and covers sub-geometries taken before SetGeometryDirectly().
But I think we can skip __del__: a sub-geometry already keeps its parent alive via _parent_geom, so only an explicit Destroy() can free the parent out from under it. What do you think?
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
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.
What does this PR do?
When getting a sub-geometry from a feature's geometry and the feature goes away, using the sub-geometry segfault:
Reproduced on 3.13.3 and master .
Fix
Each geometry a feature hands out now keep a weak reference to that feature. When you get a sub-geometry from it, the sub-geometry registered with the same feature. When the feature dies, all of them are invalidated together. Result with an exception instead of a crash, like
GetGeometryRef()case.What are related issues/pull requests?
AI tool usage
Tasklist
Environment
Provide environment details, if relevant: