Fix #119026: GPv3: Stack use after scope #119054

Merged
YimingWu merged 2 commits from ChengduLittleA/blender:fix-119026 into main 2024-03-04 15:30:18 +01:00
Member

The arrays modified_starts and modified_ends was freed early
due to wrong variable scope, this leads to incorrect randomize length
effect in length modifier. Now fixed.

The arrays `modified_starts` and `modified_ends` was freed early due to wrong variable scope, this leads to incorrect randomize length effect in length modifier. Now fixed.
YimingWu added 1 commit 2024-03-04 15:11:34 +01:00
YimingWu requested review from Falk David 2024-03-04 15:11:46 +01:00
YimingWu added the
Module
Grease Pencil
label 2024-03-04 15:11:54 +01:00
Hans Goudey requested changes 2024-03-04 15:19:32 +01:00
Dismissed
@ -128,11 +128,11 @@ static void deform_drawing(const ModifierData &md,
VArray<float> use_starts = VArray<float>::ForSingle(mmd.start_fac, curves_num);
VArray<float> use_ends = VArray<float>::ForSingle(mmd.end_fac, curves_num);
Array<float> modified_starts(curves.curves_num(), mmd.start_fac);
Member

Just declare them with the default constructor here and construct them with the necessary size and value inside the if statement.

Just declare them with the default constructor here and construct them with the necessary size and value inside the if statement.
ChengduLittleA marked this conversation as resolved
Member

I think this is a bit better. Means that you can leave the Arrays inside the if scope.

diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_length.cc b/source/blender/modifiers/intern/MOD_grease_pencil_length.cc
index c41190a2d9e..86148cb9ede 100644
--- a/source/blender/modifiers/intern/MOD_grease_pencil_length.cc
+++ b/source/blender/modifiers/intern/MOD_grease_pencil_length.cc
@@ -133,8 +133,6 @@ static void deform_drawing(const ModifierData &md,
      * branch so it could be accessed in later stretching/shrinking stages. */
     Array<float> modified_starts(curves.curves_num(), mmd.start_fac);
     Array<float> modified_ends(curves.curves_num(), mmd.end_fac);
-    use_starts = VArray<float>::ForSpan(modified_starts.as_mutable_span());
-    use_ends = VArray<float>::ForSpan(modified_ends.as_mutable_span());
 
     int seed = mmd.seed;
 
@@ -176,6 +174,9 @@ static void deform_drawing(const ModifierData &md,
         }
       }
     });
+
+    use_starts = VArray<float>::ForContainer(modified_starts);
+    use_ends = VArray<float>::ForContainer(modified_ends);
   }
 
   curves = geometry::extend_curves(curves,
I think this is a bit better. Means that you can leave the `Array`s inside the if scope. ```diff diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_length.cc b/source/blender/modifiers/intern/MOD_grease_pencil_length.cc index c41190a2d9e..86148cb9ede 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_length.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_length.cc @@ -133,8 +133,6 @@ static void deform_drawing(const ModifierData &md, * branch so it could be accessed in later stretching/shrinking stages. */ Array<float> modified_starts(curves.curves_num(), mmd.start_fac); Array<float> modified_ends(curves.curves_num(), mmd.end_fac); - use_starts = VArray<float>::ForSpan(modified_starts.as_mutable_span()); - use_ends = VArray<float>::ForSpan(modified_ends.as_mutable_span()); int seed = mmd.seed; @@ -176,6 +174,9 @@ static void deform_drawing(const ModifierData &md, } } }); + + use_starts = VArray<float>::ForContainer(modified_starts); + use_ends = VArray<float>::ForContainer(modified_ends); } curves = geometry::extend_curves(curves, ```
YimingWu added 1 commit 2024-03-04 15:24:55 +01:00
Falk David approved these changes 2024-03-04 15:27:24 +01:00
Falk David left a comment
Member

I suppose this works as well. I'm fine with either.

I suppose this works as well. I'm fine with either.
Hans Goudey approved these changes 2024-03-04 15:28:52 +01:00
Hans Goudey changed title from Fix #119026: GPv3: Fix variable scope to Fix #119026: GPv3: Stack use after scope 2024-03-04 15:29:09 +01:00
YimingWu merged commit 4f70190a01 into main 2024-03-04 15:30:18 +01:00
YimingWu deleted branch fix-119026 2024-03-04 15:30:20 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
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#119054
No description provided.