Bug 466902

Summary: Cloning undefined frames results in a crash
Product: [Applications] krita Reporter: paleh <paleh21669>
Component: AnimationAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: crash    
Priority: NOR    
Version First Reported In: 5.1.5   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: short backtrace
long backtrace

Description paleh 2023-03-05 18:31:29 UTC
Created attachment 157019 [details]
short backtrace

SUMMARY
Title. On windows it also results in an unexpected behavior, as well as a crash (see Additional Info).

STEPS TO REPRODUCE
1. Create a new paint layer A. 
2. Add a blank* frame on A.
3. By holding Shift or Ctrl select several undefined keyframe slots** in the timeline of A.
4. Right click and choose "Clone Keyframes".
5. Create a new paint layer B, add a blank frame to it.
6. Right click on B's timeline and choose "Paste Keyframes"***
 
* whether or not the frames are blank does not impact the result
** the selection needs to contain at least one undefined frame and one other frame (defined or undefined)
*** cloning by Alt+dragging does not result in a crash

OBSERVED RESULT
- krita crashes

EXPECTED RESULT
- krita doesn't crash
- pasting undefined cloned frames has no impact
- pasting an array of mixed defined and undefined cloned frames duplicates the defined frames, while undefined frames make no impact.

SOFTWARE/OS VERSIONS
Linux: Ubuntu 22.04
Qt Version: 5.12.12

ADDITIONAL INFORMATION
The issue exists on Windows in a different form. When an undefined frame is cloned (and pasted) on B, it is replaced by a duplicate of the next defined frame in the timeline of A (the expected result is that pasting undefined frames shouldn't affect the timeline of B). If no such frame exists, Krita crashes.
Comment 1 paleh 2023-03-05 18:31:58 UTC
Created attachment 157020 [details]
long backtrace
Comment 2 Dmitry Kazakov 2023-04-18 09:24:16 UTC
Git commit 3712735fa2cb13fdde9ef5e61f24a817ff24df8b by Dmitry Kazakov.
Committed on 18/04/2023 at 09:24.
Pushed by dkazakov into branch 'master'.

Make copy-frame utility function smore robust

The code that calls them doesn't check if the source keyframe
actually exists or not.

M  +8    -0    libs/image/kis_keyframe_channel.cpp

https://invent.kde.org/graphics/krita/commit/3712735fa2cb13fdde9ef5e61f24a817ff24df8b