Depsgraph: Fix 'use after free' error in some cases during undo step #106661
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#106661
Loading…
Reference in New Issue
No description provided.
Delete Branch "F-fix-deg-memuse-after-free"
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?
The root of the issue seems to be that the depsgraph stores the name
parts of its Component and Operation ID keys as string pointers, which
may reffer to some data from the underlying ID.
During undo, to reduce updates and speedup undo steps, a lot of IDs get
'replaced in place', i.e. new data read from the undo memfile is moved
into the existing 'old' ID memory address. And the depsgraph is also
re-used from the old BMain.
Calling
DEG_id_tag_update
and similar on the ID can then causedepsgraph code to access freed memory from the 'old' data.
To address this issue, this commit replaces the raw C string pointer by
an std::string for both
ComponentIDKey
andOperationIDKey
name.This has a performance cost on depsgraph building though, of about 6% to
7%. Depsgraph evaluation remains unchanged.
Depsgraph: Fix 'use after free' error in some cases during undo step.to Depsgraph: Fix 'use after free' error in some cases during undo stepThe 7% kind of sounds a lot, but the non-dangerous access to the graph nodes probably worth it.
There is a tricky way to avoid it by utilizing the fact that tagging is only interested in the components with the default name (aka, empty) and does not happen for per-bone components. We can modify the storage of such default names (use a string with known pointer, i.e.) and modify the node comparison so that it does not look into the node->name content when the name is expected to be empty (roll-back to pointer comparison in that case). It will avoid having all names heap-allocated, but makes things more tricky from the safety perspective.
Maybe we have some cheaper replacement of the
std::string
, or maybe there is another trick to solve the problem in a reliable way without a performance penalty that I am missing.This is something where I'd really like to have second pair of thoughts from @JacquesLucke and @dr.sybren.
From my side I am kind of inclined to say: if this a stopping issue and no quick alternative is found lets go with the proposed solution until a better one is found.
I agree.
There could be some optimization done by giving the calling code some more 'say' in how the name is handled.
ComponentNode::{find,get,has}_operation()
construct a temporaryOperationIDKey
for which it's fine to reuse thechar*
for comparisons. It's only when things get stored, like inComponentNode::add_operation()
, where it's important to make a copy.We could go further and let the
OperationIDKey
andOperationNode
share the same name (via astd::weak_ptr<>
or something), but I'm afraid that that'll cause more trouble than it's worth.Fixed as better solution (no more performances cost) as
ade103d7b8
, thanks!Pull request closed