Bug 433770

Summary: Crash when performing a redo action after certain crop-related steps
Product: [Applications] krita Reporter: tomtomtomreportingin
Component: GeneralAssignee: sh_zam <shzam>
Status: RESOLVED FIXED    
Severity: crash CC: ByteEnable, ghevan, halcyoen, shzam
Priority: NOR    
Version: 4.4.3-beta1   
Target Milestone: ---   
Platform: Appimage   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: backtrace

Description tomtomtomreportingin 2021-03-01 02:17:44 UTC
SUMMARY
Krita segfaults when performing a redo action after taking certain steps related to the crop tool.

STEPS TO REPRODUCE
1. Draw something.
2. Select crop tool.
3. Make a crop box.
4. Undo (this single undo will undo both the drawing and the crop box).
5. Make another crop box.
6. Redo.

Another case:
1. Select crop tool.
2. Make a crop box.
3. Crop.
4. Undo.
5. Make another crop box.
6. Redo.

OBSERVED RESULT
Krita segfaults.

EXPECTED RESULT
Krita shouldn't segfault. Perhaps the crop box selection action could be considered its own action in the undo stack as well.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Debian sid
(available in About System)
KDE Plasma Version: 5.20.5
KDE Frameworks Version: 5.78.0
Qt Version: 5.12.9 (Appimage)

ADDITIONAL INFORMATION
Not a regression, from what I can tell.
Comment 1 vanyossi 2021-03-01 04:35:21 UTC
Created attachment 136270 [details]
backtrace

I can confirm this bug, easily reproductible following the steps provided, attached backtrace.
Comment 2 sh_zam 2021-03-24 08:10:49 UTC
Can reproduce in master as well. Assigning this to myself.
Comment 3 Bug Janitor Service 2021-03-24 10:26:01 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/765
Comment 4 sh_zam 2021-03-24 10:38:49 UTC
Git commit 5ea95edb1f51acbac032055aee6333381efe95c8 by Sharaf Zaman.
Committed on 24/03/2021 at 10:22.
Pushed by szaman into branch 'master'.

Bugfix: Crash with crop tool

The reason for crash was use after free, and the flow is like this:

1. User Crops the image (Crop gets added to Undo Stack)
2. User Undos the Crop  (Crop is popped off that stack and is available
for Redo)
3. User makes a Crop Selection
4. User makes a Redo Action (Because the crop selection is active, prior
to the change we would apply the crop stroke which would purge the Redo
Stack, deleting the KisSavedMacroCommand* which later would be used in
KisSavedCommandBase::runStroke [its vtable]).

Since there is no stroke running during selection, we only have to clear
the selection.

M  +1    -1    plugins/tools/tool_crop/kis_tool_crop.cc

https://invent.kde.org/graphics/krita/commit/5ea95edb1f51acbac032055aee6333381efe95c8
Comment 5 sh_zam 2021-03-24 10:39:26 UTC
Git commit 9ac750ab57607f3219ca4d444bc1e9ec69517e67 by Sharaf Zaman.
Committed on 24/03/2021 at 10:39.
Pushed by szaman into branch 'krita/4.3'.

Bugfix: Crash with crop tool

The reason for crash was use after free, and the flow is like this:

1. User Crops the image (Crop gets added to Undo Stack)
2. User Undos the Crop  (Crop is popped off that stack and is available
for Redo)
3. User makes a Crop Selection
4. User makes a Redo Action (Because the crop selection is active, prior
to the change we would apply the crop stroke which would purge the Redo
Stack, deleting the KisSavedMacroCommand* which later would be used in
KisSavedCommandBase::runStroke [its vtable]).

Since there is no stroke running during selection, we only have to clear
the selection.


(cherry picked from commit 5ea95edb1f51acbac032055aee6333381efe95c8)

M  +1    -1    plugins/tools/tool_crop/kis_tool_crop.cc

https://invent.kde.org/graphics/krita/commit/9ac750ab57607f3219ca4d444bc1e9ec69517e67
Comment 6 Halcyoen 2021-04-01 16:00:19 UTC
*** Bug 435193 has been marked as a duplicate of this bug. ***
Comment 7 Dmitry Kazakov 2021-04-03 11:54:36 UTC
Git commit a993eec3de6487ea01b712c4695503f880ee673f by Dmitry Kazakov.
Committed on 03/04/2021 at 11:53.
Pushed by dkazakov into branch 'master'.

Fix data corruption on pressing Ctrl+Z while crop action is active

M  +5    -0    plugins/tools/tool_crop/kis_tool_crop.cc
M  +1    -0    plugins/tools/tool_crop/kis_tool_crop.h

https://invent.kde.org/graphics/krita/commit/a993eec3de6487ea01b712c4695503f880ee673f
Comment 8 Dmitry Kazakov 2021-06-01 13:14:40 UTC
Git commit 2eb56697e4646d34fe5f0b940ec0bc991d589a9b by Dmitry Kazakov.
Committed on 01/06/2021 at 11:58.
Pushed by dkazakov into branch 'krita/4.3'.

Fix data corruption on pressing Ctrl+Z while crop action is active

M  +5    -0    plugins/tools/tool_crop/kis_tool_crop.cc
M  +1    -0    plugins/tools/tool_crop/kis_tool_crop.h

https://invent.kde.org/graphics/krita/commit/2eb56697e4646d34fe5f0b940ec0bc991d589a9b
Comment 9 sh_zam 2021-06-20 12:42:08 UTC
*** Bug 438563 has been marked as a duplicate of this bug. ***