WIP: Add a mechanism to abort a blend file reading on critical error. #105085

Closed
Bastien Montagne wants to merge 1 commits from mont29:F-abort-file-reading into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

This commit introduces a C++-exception based mechanism to abort a blend
file reading.

The generated BMain is then marked as invalid, and calling code (like
e.g. #BKE_blendfile_read etc.) will not proceed in such case.

This is an implementation of the #105083 design task.


TODOs:

Check further about usages of BLO_read_from_file, this patch should
cover 'regular' blendfile reading and linking/appending code, but
another check pass is needed here.

Write tests to validate at least the basics of this new mechanism.


Some notes:

This commit also has a fix to Main freeing function in case it is in
'split' state. This should be committed separately.

There is a memleak from read_libblock, not clear whether this is caused
by the forged .blend file or this patch yet.

The only actual change currently is adding a check on bScreen->scene
pointer being non-NULL (related to #99836), but we likely want way more
usages of this 'abort fileread'.

Given the extense of the change, I do not think this should be
considered for 3.5 and previous LTS releases. For these a simple 'check
and assign first available scene' "fix" would probably be enough to
address #99836 ?

This commit introduces a C++-exception based mechanism to abort a blend file reading. The generated BMain is then marked as invalid, and calling code (like e.g. #BKE_blendfile_read etc.) will not proceed in such case. This is an implementation of the #105083 design task. ------------------------------ TODOs: Check further about usages of `BLO_read_from_file`, this patch should cover 'regular' blendfile reading and linking/appending code, but another check pass is needed here. Write tests to validate at least the basics of this new mechanism. ------------------------------ Some notes: This commit also has a fix to Main freeing function in case it is in 'split' state. This should be committed separately. There is a memleak from `read_libblock`, not clear whether this is caused by the forged .blend file or this patch yet. The only actual change currently is adding a check on bScreen->scene pointer being non-NULL (related to #99836), but we likely want way more usages of this 'abort fileread'. Given the extense of the change, I do not think this should be considered for 3.5 and previous LTS releases. For these a simple 'check and assign first available scene' "fix" would probably be enough to address #99836 ?
Bastien Montagne added this to the Core project 2023-02-22 18:01:44 +01:00
Bastien Montagne added the
Module
Core
label 2023-02-22 18:02:17 +01:00

I'm unsure about using exceptions in code that is still written in C style. This can lead to memory leaks and hanging mutex locks, and you can't tell from looking at any function by itself that it needs to using RAII.

Is it possible to have more explicit C style error checking? I don't know how deep these call stacks go and how many functions this affects.

I'm unsure about using exceptions in code that is still written in C style. This can lead to memory leaks and hanging mutex locks, and you can't tell from looking at any function by itself that it needs to using RAII. Is it possible to have more explicit C style error checking? I don't know how deep these call stacks go and how many functions this affects.
Author
Owner

@brecht this is certainly possible, but it will then become way more verbose and intrusive, since basically each level of the call stack would need to periodically check the error status/flag to abort the reading... And even then, it would not give us the same 'instant abort' behavior as the one we get with exceptions...

@brecht this is certainly possible, but it will then become way more verbose and intrusive, since basically each level of the call stack would need to periodically check the error status/flag to abort the reading... And even then, it would not give us the same 'instant abort' behavior as the one we get with exceptions...

I'm fine with catching exceptions as a fallback, but don't think we should be throwing them.

It would be more verbose to use error checking, but as far as I can tell this patch adds just one BLO_read_assert_message, and all we have to do is go up the call stack and add some tests for that case, meanwhile checking there are no memory leaks or hanging mutex locks in those functions?

I didn't understand why it would not be as instant.

I'm fine with catching exceptions as a fallback, but don't think we should be throwing them. It would be more verbose to use error checking, but as far as I can tell this patch adds just one `BLO_read_assert_message`, and all we have to do is go up the call stack and add some tests for that case, meanwhile checking there are no memory leaks or hanging mutex locks in those functions? I didn't understand why it would not be as instant.
Bastien Montagne force-pushed F-abort-file-reading from b9a626007a to bfdcd8de3a 2023-02-27 18:17:27 +01:00 Compare
Author
Owner

Updated to use the new main invalid flag and check it in a few 'critical' places, instead of using exceptions... This will get way more verbose if we keep adding these in the future.

Updated to use the new main invalid flag and check it in a few 'critical' places, instead of using exceptions... This will get way more verbose if we keep adding these in the future.
Brecht Van Lommel requested changes 2023-02-28 10:27:04 +01:00
@ -3604,1 +3635,4 @@
main->is_locked_for_linking = false;
return;
}
do_versions_after_linking_cycles(main);

I suggest to write it like this instead of returning early and having main->is_locked_for_linking = false duplicated.

if (!main->is_read_invalid) {
  do_versions_after_linking_280(fd, main);
}
if (!main->is_read_invalid) {
 do_versions_after_linking_290(fd, main);
}
...

And to do this for every do_versions, even if not needed now I think there is some chance of this getting overlooked in the future.

I suggest to write it like this instead of returning early and having `main->is_locked_for_linking = false` duplicated. ``` if (!main->is_read_invalid) { do_versions_after_linking_280(fd, main); } if (!main->is_read_invalid) { do_versions_after_linking_290(fd, main); } ... ``` And to do this for every `do_versions`, even if not needed now I think there is some chance of this getting overlooked in the future.
mont29 marked this conversation as resolved
Bastien Montagne force-pushed F-abort-file-reading from bfdcd8de3a to 3dc8035e1f 2023-02-28 18:29:58 +01:00 Compare
Brecht Van Lommel approved these changes 2023-02-28 18:45:00 +01:00
Author
Owner

Committed as 3e5ce23c99, b3f42d8e98 and 1ed783eed3.

Committed as 3e5ce23c99, b3f42d8e98 and 1ed783eed3.
Bastien Montagne closed this pull request 2023-03-01 11:52:39 +01:00
Bastien Montagne deleted branch F-abort-file-reading 2023-03-01 11:52:54 +01:00
Bastien Montagne removed this from the Core project 2023-07-03 12:48:29 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105085
No description provided.