Bug 441945 - File Layers not working when opened with "folder icon"
Summary: File Layers not working when opened with "folder icon"
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Layer Stack (other bugs)
Version First Reported In: 5.0.0-beta1
Platform: Compiled Sources All
: NOR crash
Target Milestone: ---
Assignee: Dmitry Kazakov
URL:
Keywords: regression, release_blocker
Depends on:
Blocks:
 
Reported: 2021-09-03 10:04 UTC by SirPigeonz
Modified: 2021-12-17 09:52 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
test files (3.69 MB, application/x-7z-compressed)
2021-09-03 10:04 UTC, SirPigeonz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description SirPigeonz 2021-09-03 10:04:19 UTC
Created attachment 141266 [details]
test files

SUMMARY

I tried to use File Layers feature but found it not working as expected.
Creation of a file layer either by converting or manual setup works.

If I open sub-file with File Layer folder icon it breaks something and I can't edit sub-file.

Problem is that file used as a File Layer in the main document are not saved or can't be edited properly after.

I found that I can't edit sub-file if I don't restart main-file and sub-file.


Things that I found not working are:
1. Adding new layer in sub-file
2. Changing layers properties in the sub-file
3. Saving editet layer data in a sub-file
4. File layer in main-file is not updated


STEPS TO REPRODUCE
1. Create Main Document
2. Create Sub Document that will be used as a File Layer
3. Create some layers in Sub Document
4. Add Sub Document as a File Layer in Main Document
5. Close sub-doc
6. Open sub-doc using "folder icon" in main-doc
7. Try editing layer data or properies in sub-doc
8. Try adding new layer in sub-doc
9. Try saving sub-doc

OBSERVED RESULT

You can't edit layer properties/data or add new layers.
Saving sub-doc is not working.

EXPECTED RESULT


You can edit sub-doc as a normal file and save it.
Main-doc updates File Layer when sub-doc is saved.

Krita

 Version: 5.0.0-beta1
 Languages: en_GB, en, en_US, en, en_GB, en, en_US, en, en_GB, en, en_US, en, en_GB, en, en_US, en, en_GB, en, en_US, en
 Hidpi: false

Qt

  Version (compiled): 5.12.11
  Version (loaded): 5.12.11

OS Information

  Build ABI: x86_64-little_endian-llp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: winnt
  Kernel Version: 10.0.19043
  Pretty Productname: Windows 10 (10.0)
  Product Type: windows
  Product Version: 10

OpenGL Info
 
  Vendor:  "Google Inc." 
  Renderer:  "ANGLE (NVIDIA GeForce GTX 1070 Direct3D11 vs_5_0 ps_5_0)" 
  Version:  "OpenGL ES 3.0 (ANGLE 2.1.0.57ea533f79a7)" 
  Shading language:  "OpenGL ES GLSL ES 3.00 (ANGLE 2.1.0.57ea533f79a7)" 
  Requested format:  QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::CompatibilityProfile) 
  Current format:    QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::DefaultSwapBehavior, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile) 
     Version: 3.0
     Supports deprecated functions false 
     is OpenGL ES: true 

QPA OpenGL Detection Info 
  supportsDesktopGL: true 
  supportsAngleD3D11: true 
  isQtPreferAngle: true 

Hardware Information

  GPU Acceleration: angle
  Memory: 16320 Mb
  Number of Cores: 8
  Swap Location: C:/Users/pigeon/AppData/Local/Temp

Current Settings

  Current Swap Location: C:/Users/pigeon/AppData/Local/Temp
  Current Swap Location writable: true
  Undo Enabled: true
  Undo Stack Limit: 30
  Use OpenGL: true
  Use OpenGL Texture Buffer: true
  Disable Vector Optimizations: false
  Disable AVX Optimizations: false
  Canvas State: OPENGL_SUCCESS
  Autosave Interval: 900
  Use Backup Files: true
  Number of Backups Kept: 1
  Backup File Suffix: ~
  Backup Location: Same Folder as the File
  Backup Location writable: false
  Use Win8 Pointer Input: false
  Use RightMiddleTabletButton Workaround: false
  Levels of Detail Enabled: false
  Use Zip64: false


Display Information
Number of screens: 2
	Screen: 0
		Name: \\.\DISPLAY1
		Depth: 32
		Scale: 1
		Resolution in pixels: 1920x1080
		Manufacturer: 
		Model: 
		Refresh Rate: 60
	Screen: 1
		Name: \\.\DISPLAY2
		Depth: 32
		Scale: 1
		Resolution in pixels: 1920x1080
		Manufacturer: 
		Model: 
		Refresh Rate: 60


---------------------
================================================================================
SESSION: 23 Jul 2019 08:52:40 +0200. Executing C:\Program Files\Krita (x64)\bin\krita.exe

ADDITIONAL INFORMATION
Comment 1 Ahab Greybeard 2021-09-12 16:02:41 UTC
I can confirm this with the 5.0.0-beta1 appimage and the Sept 11 5.1.0-prealpha (git 1419c7c) appimage on Debian 10.

These problems do not happen with the 4.4.8 appimage, hence regression.

For the attached folder containing test files, I opened main.kra and then, using the Layers docker folder icon, I opened File Layer 3 i.e. main_Group 4.kra and tried to make changes.

I could paint in paint layers but after Saving, those paint strokes did not show in main.kra.

In main_Group 4.kra, I could not add layers.
If I deleted a layer, that content vanished from the canvas but the layer still showed in the Layers docker.
Saving and reopening showed that the painted layer changes had not been Saved.

Opening a File Layer file using File -> Open gave a document that could be edited and have layers added and deleted, then after a Save operation those changes showed in the main.doc.
Comment 2 vanyossi 2021-09-20 14:11:58 UTC
Folder icon action takes an unconventional route to open a file, using KisPart::openExistingFile. This is done without doing any checks which with a user modifiable input caused (before a quick patch I made) an instant crash if the path was modified to a non existant one.

This makes me suspect this bug in particular is caused by a missing SIGNAL after opening.
Comment 3 Halla Rempt 2021-12-14 14:03:37 UTC
I wonder why I assigned this to myself? Ivan, do you remember?

Also, there's something pretty weird going on when I click the folder icon:

krita(3366451)/(default) unknown: QSqlDatabasePrivate::database: requested database does not belong to the calling thread.
krita(3366451)/(default) unknown: QSqlQuery::prepare: database not open
krita(3366451)/(default) KisResourceCacheDb::addStorage: Could not select from storages
krita(3366451)/(default) KisResourceLocator::addStorage: ("Could not add {cba63b05-5027-47d7-b240-244c2fe15a56} to the database")
krita(3366451)/(default) unknown: QSqlDatabasePrivate::database: requested database does not belong to the calling thread.
krita(3366451)/(default) unknown: QSqlQuery::prepare: database not open
krita(3366451)/(default) KisResourceCacheDb::addStorage: Could not select from storages
krita(3366451)/(default) KisResourceLocator::addStorage: ("Could not add {cba63b05-5027-47d7-b240-244c2fe15a56} to the database", "Could not add {284f35d6-1183-42e3-a8dc-18cb2390d5a8} to the database")
krita(3366451)/(default) unknown: QObject::startTimer: Timers cannot be started from another thread
krita(3366451)/(default) unknown: QObject: Cannot create children for a parent that is in a different thread.
(Parent is QActionGroup(0x55cc8ccb1000), parent's thread is QThread(0x55cc865a36e0), current thread is QThread(0x7ff478010ed0)
Comment 4 Dmitry Kazakov 2021-12-16 13:53:29 UTC
I can actually make Krita hang up when saving the file opened this way:

1) Open a file using Folder icon
2) Paint on the opened file (the file is **not** marked which is a bug)
3) Try to press Ctrl+S, nothing happens
4) Save As into the same file, the saving succeeds
5) Close the document, Krita hangs up

Thread 1 (Thread 0x7f74b8bca8c0 (LWP 1241)):
#0  0x00007f74b4f6384d in poll () at ../sysdeps/unix/syscall-template.S:84
No locals.
#1  0x00007f74ae44745c in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
No symbol table info available.
#2  0x00007f74ae44756c in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
No symbol table info available.
#3  0x00007f74b5b0e7cf in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5
No symbol table info available.
#4  0x00007f74b864c9aa in KisAsyncActionFeedback::waitForMutex (this=<optimized out>, mutex=0x7f7450021e70) at /home/appimage/appimage-workspace/deps/usr/include/QtCore/qcoreapplication.h:116
No locals.
#5  0x00007f74b8626bf2 in KisDocument::waitForSavingToComplete (this=0x7f74500ac050) at /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:2480
        f = {m_d = {d = 0xf24fd70}}
#6  0x00007f74b868b81b in KisView::queryClose (this=0xd618140) at /home/appimage/persistent/krita/libs/ui/KisView.cpp:725
No locals.
#7  0x00007f74b868bd58 in KisView::closeEvent (this=0xd618140, event=0x7ffe70539b90) at /home/appimage/persistent/krita/libs/ui/KisView.cpp:711
        viewCount = <optimized out>
#8  0x00007f74b65993b8 in QWidget::event(QEvent*) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5
No symbol table info available.
#9  0x00007f74b65588dc in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5
No symbol table info available.
#10 0x00007f74b655ff20 in QApplication::notify(QObject*, QEvent*) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5
No symbol table info available.
#11 0x00007f74b86184c0 in KisApplication::notify (this=0x7ffe7053b5c0, receiver=<optimized out>, event=0x7ffe70539b90) at /home/appimage/persistent/krita/libs/ui/KisApplication.cpp:756
        guard = {m_info = 0x250ad60}
        result = true
        info = @0x250ad60: {eventRecursionCount = 4, postponedSynchronizationEvents = {c = {<std::_Deque_base<KisSynchronizedConnectionEvent, std::allocator<KisSynchronizedConnectionEvent> >> = {_M_impl = {<std::allocator<KisSynchronizedConnectionEvent>> = {<__gnu_cxx::new_allocator<KisSynchronizedConnectionEvent>> = {<No data fields>}, <No data fields>}, _M_map = 0x2346290, _M_map_size = 8, _M_start = {_M_cur = 0x3a3b870, _M_first = 0x3a3b870, _M_last = 0x3a3ba50, _M_node = 0x23462a8}, _M_finish = {_M_cur = 0x3a3b870, _M_first = 0x3a3b870, _M_last = 0x3a3ba50, _M_node = 0x23462a8}}}, <No data fields>}}}
        __PRETTY_FUNCTION__ = "virtual bool KisApplication::notify(QObject*, QEvent*)"
#12 0x00007f74b5ab54a8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5
No symbol table info available.
#13 0x00007f74b65945e6 in QWidgetPrivate::close_helper(QWidgetPrivate::CloseMode) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5
No symbol table info available.
#14 0x00007f74b66c54b4 in QMdiSubWindow::closeEvent(QCloseEvent*) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5
No symbol table info available.
#15 0x00007f74b65993b8 in QWidget::event(QEvent*) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5
No symbol table info available.
#16 0x00007f74b66c485b in QMdiSubWindow::event(QEvent*) () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5
No symbol table info available.
Comment 5 Dmitry Kazakov 2021-12-17 07:49:27 UTC
There is something really wrong with file layers...

=================================================================
==25681==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b000cebe70 at pc 0x7ffff29f55b6 bp 0x7fffffff8000 sp 0x7fffffff7ff0
READ of size 8 at 0x60b000cebe70 thread T0
    #0 0x7ffff29f55b5 in KisImage::copyFromImageImpl(KisImage const&, int) /home/appimage/persistent/krita/libs/image/kis_image.cc:397
    #1 0x7ffff29f7c39 in KisImage::KisImage(KisImage const&, KisUndoStore*, bool) /home/appimage/persistent/krita/libs/image/kis_image.cc:488
    #2 0x7ffff29f7e4e in KisImage::clone(bool) /home/appimage/persistent/krita/libs/image/kis_image.cc:346
    #3 0x7ffff6303b2c in KisDocument::copyFromDocumentImpl(KisDocument const&, KisDocument::CopyPolicy) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1115
    #4 0x7ffff6305f08 in KisDocument::KisDocument(KisDocument const&, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:614
    #5 0x7ffff6310a5d in KisDocument::Private::lockAndCloneImpl(bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1056
    #6 0x7ffff6310d65 in KisDocument::lockAndCloneForSaving() /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1067
    #7 0x7ffff6312363 in KisDocument::initiateSavingInBackground(QString, QObject const*, char const*, KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, std::unique_ptr<KisDocument, std::default_delete<KisDocument> >&&, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1208
    #8 0x7ffff6312bd9 in KisDocument::initiateSavingInBackground(QString, QObject const*, char const*, KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1193
    #9 0x7ffff6313520 in KisDocument::exportDocumentImpl(KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:773
    #10 0x7ffff631a21a in KisDocument::saveAs(QString const&, QByteArray const&, bool, KisPinnedSharedPtr<KisPropertiesConfiguration>) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:831
    #11 0x7ffff63b1cb0 in KisMainWindow::saveDocument(KisDocument*, bool, bool, bool) /home/appimage/persistent/krita/libs/ui/KisMainWindow.cpp:1449
    #12 0x7ffff63b45f5 in KisMainWindow::slotFileSave() /home/appimage/persistent/krita/libs/ui/KisMainWindow.cpp:1747
    #13 0x7ffff63d74bc in KisMainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) /home/appimage/appimage-workspace/krita-build/libs/ui/kritaui_autogen/include/moc_KisMainWindow.cpp:377
    #14 0x7fffe86df858 in QMetaObject::activate(QObject*, int, int, void**) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x2b4858)
    #15 0x7fffe914f351 in QAction::triggered(bool) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5+0x15c351)
    #16 0x7fffe91518df in QAction::activate(QAction::ActionEvent) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5+0x15e8df)
    #17 0x7fffe9152243 in QAction::event(QEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5+0x15f243)
    #18 0x7fffe91558db in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5+0x1628db)
    #19 0x7fffe915cf1f in QApplication::notify(QObject*, QEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5+0x169f1f)
    #20 0x7ffff62b27d9 in KisApplication::notify(QObject*, QEvent*) /home/appimage/persistent/krita/libs/ui/KisApplication.cpp:756
    #21 0x7fffe86b24a7 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x2874a7)
    #22 0x7fffe8b532f0 in QShortcutMap::dispatchEvent(QKeyEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Gui.so.5+0x1772f0)
    #23 0x7fffe8b533a8 in QShortcutMap::tryShortcut(QKeyEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Gui.so.5+0x1773a8)
    #24 0x7fffe8b09c56 in QWindowSystemInterface::handleShortcutEvent(QWindow*, unsigned long, int, QFlags<Qt::KeyboardModifier>, unsigned int, unsigned int, unsigned int, QString const&, bool, unsigned short) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Gui.so.5+0x12dc56)
    #25 0x7fffe8b2522b in QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Gui.so.5+0x14922b)
    #26 0x7fffe8b2a174 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Gui.so.5+0x14e174)
    #27 0x7fffe8b0639a in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Gui.so.5+0x12a39a)
    #28 0x7fffdbc78fb9  (/home/appimage/appimage-workspace/deps/usr/lib/libQt5XcbQpa.so.5+0x6afb9)
    #29 0x7fffe4e6b266 in g_main_context_dispatch (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4a266)
    #30 0x7fffe4e6b4bf  (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4a4bf)
    #31 0x7fffe4e6b56b in g_main_context_iteration (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4a56b)
    #32 0x7fffe870b7ce in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x2e07ce)
    #33 0x7fffe86b0a39 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x285a39)
    #34 0x7fffe86b97b3 in QCoreApplication::exec() (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x28e7b3)
    #35 0x412430 in main /home/appimage/persistent/krita/krita/main.cc:698
    #36 0x7fffe755f83f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2083f)
    #37 0x415728 in _start (/home/appimage/appimage-workspace/krita.appdir/usr/bin/krita+0x415728)

0x60b000cebe70 is located 96 bytes inside of 104-byte region [0x60b000cebe10,0x60b000cebe78)
freed by thread T0 here:
    #0 0x7ffff72b70a5 in operator delete(void*, unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10f0a5)
    #1 0x7ffff29f8d9e in KisImage::~KisImage() /home/appimage/persistent/krita/libs/image/kis_image.cc:274
    #2 0x7ffff5596dd9 in KisSharedPtr<KisImage>::deref(KisSharedPtr<KisImage> const*, KisImage*) /home/appimage/persistent/krita/libs/global/kis_shared_ptr.h:199
    #3 0x7ffff5596dd9 in KisSharedPtr<KisImage>::deref() const /home/appimage/persistent/krita/libs/global/kis_shared_ptr.h:213
    #4 0x7ffff5596dd9 in KisSharedPtr<KisImage>::~KisSharedPtr() /home/appimage/persistent/krita/libs/global/kis_shared_ptr.h:97
    #5 0x7ffff5596dd9 in KisFileLayer::slotLoadingFinished(KisSharedPtr<KisPaintDevice>, double, double, QSize const&) /home/appimage/persistent/krita/libs/ui/kis_file_layer.cpp:192
    #6 0x7ffff4fe5a9f in KisFileLayer::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) /home/appimage/appimage-workspace/krita-build/libs/ui/kritaui_autogen/EWIEGA46WW/moc_kis_file_layer.cpp:78
    #7 0x7fffe86df858 in QMetaObject::activate(QObject*, int, int, void**) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x2b4858)
    #8 0x7ffff4fb5984 in KisSafeDocumentLoader::loadingFinished(KisSharedPtr<KisPaintDevice>, double, double, QSize const&) /home/appimage/appimage-workspace/krita-build/libs/ui/kritaui_autogen/EWIEGA46WW/moc_kis_safe_document_loader.cpp:169
    #9 0x7ffff55adf49 in KisSafeDocumentLoader::delayedLoadStart() /home/appimage/persistent/krita/libs/ui/kis_safe_document_loader.cpp:321
    #10 0x7ffff55b2d05 in KisSafeDocumentLoader::fileChangedCompressed(bool) /home/appimage/persistent/krita/libs/ui/kis_safe_document_loader.cpp:247
    #11 0x7ffff55b313d in KisSafeDocumentLoader::reloadImage() /home/appimage/persistent/krita/libs/ui/kis_safe_document_loader.cpp:207
    #12 0x7ffff55933a6 in KisFileLayer::setImage(KisWeakSharedPtr<KisImage>) /home/appimage/persistent/krita/libs/ui/kis_file_layer.cpp:263
    #13 0x7ffff2d113fa in operator() /home/appimage/persistent/krita/libs/image/kis_node.cpp:265
    #14 0x7ffff2d113fa in recursiveApplyNodes<KisSharedPtr<KisNode>, KisNode::setImage(KisImageWSP)::<lambda(KisNodeSP)> > /home/appimage/persistent/krita/libs/image/kis_layer_utils.h:204
    #15 0x7ffff2d1b5f5 in KisNode::setImage(KisWeakSharedPtr<KisImage>) /home/appimage/persistent/krita/libs/image/kis_node.cpp:263
    #16 0x7ffff2a929bb in KisLayer::setImage(KisWeakSharedPtr<KisImage>) /home/appimage/persistent/krita/libs/image/kis_layer.cc:384
    #17 0x7ffff298ff6f in KisGroupLayer::setImage(KisWeakSharedPtr<KisImage>) /home/appimage/persistent/krita/libs/image/kis_group_layer.cc:151
    #18 0x7ffff29f2cf8 in KisImage::copyFromImageImpl(KisImage const&, int) /home/appimage/persistent/krita/libs/image/kis_image.cc:396
    #19 0x7ffff29f7c39 in KisImage::KisImage(KisImage const&, KisUndoStore*, bool) /home/appimage/persistent/krita/libs/image/kis_image.cc:488
    #20 0x7ffff29f7e4e in KisImage::clone(bool) /home/appimage/persistent/krita/libs/image/kis_image.cc:346
    #21 0x7ffff6303b2c in KisDocument::copyFromDocumentImpl(KisDocument const&, KisDocument::CopyPolicy) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1115
    #22 0x7ffff6305f08 in KisDocument::KisDocument(KisDocument const&, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:614
    #23 0x7ffff6310a5d in KisDocument::Private::lockAndCloneImpl(bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1056
    #24 0x7ffff6310d65 in KisDocument::lockAndCloneForSaving() /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1067
    #25 0x7ffff6312363 in KisDocument::initiateSavingInBackground(QString, QObject const*, char const*, KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, std::unique_ptr<KisDocument, std::default_delete<KisDocument> >&&, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1208
    #26 0x7ffff6312bd9 in KisDocument::initiateSavingInBackground(QString, QObject const*, char const*, KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1193
    #27 0x7ffff6313520 in KisDocument::exportDocumentImpl(KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:773
    #28 0x7ffff631a21a in KisDocument::saveAs(QString const&, QByteArray const&, bool, KisPinnedSharedPtr<KisPropertiesConfiguration>) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:831
    #29 0x7ffff63b1cb0 in KisMainWindow::saveDocument(KisDocument*, bool, bool, bool) /home/appimage/persistent/krita/libs/ui/KisMainWindow.cpp:1449
    #30 0x7ffff63b45f5 in KisMainWindow::slotFileSave() /home/appimage/persistent/krita/libs/ui/KisMainWindow.cpp:1747
    #31 0x7ffff63d74bc in KisMainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) /home/appimage/appimage-workspace/krita-build/libs/ui/kritaui_autogen/include/moc_KisMainWindow.cpp:377
    #32 0x7fffe86df858 in QMetaObject::activate(QObject*, int, int, void**) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x2b4858)
    #33 0x7fffe914f351 in QAction::triggered(bool) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5+0x15c351)

previously allocated by thread T0 here:
    #0 0x7ffff72b59df in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10d9df)
    #1 0x7ffff29f7e3b in KisImage::clone(bool) /home/appimage/persistent/krita/libs/image/kis_image.cc:346
    #2 0x7ffff6303b2c in KisDocument::copyFromDocumentImpl(KisDocument const&, KisDocument::CopyPolicy) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1115
    #3 0x7ffff6305f08 in KisDocument::KisDocument(KisDocument const&, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:614
    #4 0x7ffff6310a5d in KisDocument::Private::lockAndCloneImpl(bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1056
    #5 0x7ffff6310d65 in KisDocument::lockAndCloneForSaving() /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1067
    #6 0x7ffff6312363 in KisDocument::initiateSavingInBackground(QString, QObject const*, char const*, KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, std::unique_ptr<KisDocument, std::default_delete<KisDocument> >&&, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1208
    #7 0x7ffff6312bd9 in KisDocument::initiateSavingInBackground(QString, QObject const*, char const*, KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:1193
    #8 0x7ffff6313520 in KisDocument::exportDocumentImpl(KritaUtils::ExportFileJob const&, KisPinnedSharedPtr<KisPropertiesConfiguration>, bool) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:773
    #9 0x7ffff631a21a in KisDocument::saveAs(QString const&, QByteArray const&, bool, KisPinnedSharedPtr<KisPropertiesConfiguration>) /home/appimage/persistent/krita/libs/ui/KisDocument.cpp:831
    #10 0x7ffff63b1cb0 in KisMainWindow::saveDocument(KisDocument*, bool, bool, bool) /home/appimage/persistent/krita/libs/ui/KisMainWindow.cpp:1449
    #11 0x7ffff63b45f5 in KisMainWindow::slotFileSave() /home/appimage/persistent/krita/libs/ui/KisMainWindow.cpp:1747
    #12 0x7ffff63d74bc in KisMainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) /home/appimage/appimage-workspace/krita-build/libs/ui/kritaui_autogen/include/moc_KisMainWindow.cpp:377
    #13 0x7fffe86df858 in QMetaObject::activate(QObject*, int, int, void**) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5+0x2b4858)
    #14 0x7fffe914f351 in QAction::triggered(bool) (/home/appimage/appimage-workspace/deps/usr/lib/libQt5Widgets.so.5+0x15c351)

SUMMARY: AddressSanitizer: heap-use-after-free /home/appimage/persistent/krita/libs/image/kis_image.cc:397 in KisImage::copyFromImageImpl(KisImage const&, int)
Shadow bytes around the buggy address:
  0x0c1680195770: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa
  0x0c1680195780: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa
  0x0c1680195790: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
  0x0c16801957a0: fd fd fd fd fa fa fa fa fa fa fa fa fd fd fd fd
  0x0c16801957b0: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
=>0x0c16801957c0: fa fa fd fd fd fd fd fd fd fd fd fd fd fd[fd]fa
  0x0c16801957d0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c16801957e0: 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fd fd
  0x0c16801957f0: fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa
  0x0c1680195800: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1680195810: fd fd fa fa fa fa fa fa fa fa fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==25681==ABORTING
Comment 6 Dmitry Kazakov 2021-12-17 09:50:58 UTC
Git commit a06de5df135c14d8335b0589d0099e85d94f316d by Dmitry Kazakov.
Committed on 17/12/2021 at 09:50.
Pushed by dkazakov into branch 'master'.

Fix memory corruptions (and crashes) in File Layers

1) When we copy the image on saving, we will call KisFileLayer::setImage(),
   which transitively calls to KisFileLayer::slotLoadingFinished(), which
   could convert the image pointer to the strong one. That could cause a
   crash, because the image was not constructed yet, therefore its
   refernce counter was still zero.

2) When we copy the layer into the clipboard and destroy its (temporary)
   image, we should clear all the references to this layer, such as
   KisNode::image() and KisNode::graphListener(). Otherwise it could
   cause a memory corruption, when the layer in the clipboard could
   call setDirty() on the external image change.
Related: bug 446209

M  +3    -0    libs/image/kis_image.cc
M  +3    -1    libs/ui/flake/kis_shape_layer.cc
M  +27   -2    libs/ui/kis_file_layer.cpp

https://invent.kde.org/graphics/krita/commit/a06de5df135c14d8335b0589d0099e85d94f316d
Comment 7 Dmitry Kazakov 2021-12-17 09:51:06 UTC
Git commit 69d3d5c7391efda4d0637d7e404be2e86ed946ad by Dmitry Kazakov.
Committed on 17/12/2021 at 09:50.
Pushed by dkazakov into branch 'master'.

Fix editing a file opened via file layer's folder icon

The document was created in the non-gui thread, which broke all the
signal connections.

M  +4    -1    libs/ui/kis_file_layer.cpp
M  +6    -2    libs/ui/kis_file_layer.h

https://invent.kde.org/graphics/krita/commit/69d3d5c7391efda4d0637d7e404be2e86ed946ad
Comment 8 Dmitry Kazakov 2021-12-17 09:52:36 UTC
Git commit 7a2b01464d96e4b93a8399fc002b5737b04c621a by Dmitry Kazakov.
Committed on 17/12/2021 at 09:51.
Pushed by dkazakov into branch 'krita/5.0'.

Fix editing a file opened via file layer's folder icon

The document was created in the non-gui thread, which broke all the
signal connections.

M  +4    -1    libs/ui/kis_file_layer.cpp
M  +6    -2    libs/ui/kis_file_layer.h

https://invent.kde.org/graphics/krita/commit/7a2b01464d96e4b93a8399fc002b5737b04c621a
Comment 9 Dmitry Kazakov 2021-12-17 09:52:44 UTC
Git commit 763bd11a7eb85953afc101a00882d27b2d69a07a by Dmitry Kazakov.
Committed on 17/12/2021 at 09:51.
Pushed by dkazakov into branch 'krita/5.0'.

Fix memory corruptions (and crashes) in File Layers

1) When we copy the image on saving, we will call KisFileLayer::setImage(),
   which transitively calls to KisFileLayer::slotLoadingFinished(), which
   could convert the image pointer to the strong one. That could cause a
   crash, because the image was not constructed yet, therefore its
   refernce counter was still zero.

2) When we copy the layer into the clipboard and destroy its (temporary)
   image, we should clear all the references to this layer, such as
   KisNode::image() and KisNode::graphListener(). Otherwise it could
   cause a memory corruption, when the layer in the clipboard could
   call setDirty() on the external image change.
Related: bug 446209

M  +3    -0    libs/image/kis_image.cc
M  +3    -1    libs/ui/flake/kis_shape_layer.cc
M  +27   -2    libs/ui/kis_file_layer.cpp

https://invent.kde.org/graphics/krita/commit/763bd11a7eb85953afc101a00882d27b2d69a07a