Bug 443904

Summary: Crash on invalid pattern file
Product: [Applications] krita Reporter: Tiar <tamtamy.tymona>
Component: File formatsAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: git master (please specify the git hash!)   
Target Milestone: ---   
Platform: Mint (Ubuntu based)   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Test pattern file

Description Tiar 2021-10-17 19:31:35 UTC
Created attachment 142537 [details]
Test pattern file

SUMMARY
If Krita encounters a pattern file with a wrong file suffix, it will crash because of trying incompatible data.

STEPS TO REPRODUCE
1. Put the test file pattern into your `patterns/` folder in resource folder (note that it must have endinf `.png.pat`).
2. Start Krita in gdb.
3. See the crash.

OBSERVED RESULT
Crash

EXPECTED RESULT
No crash

SOFTWARE/OS VERSIONS
Krita

 Version: 5.1.0-prealpha (git ae9a8ff)
 Languages: en_US, en, en_US, en, en_US, en, pl_PL, pl, pl_PL, pl
 Hidpi: true

Qt

  Version (compiled): 5.11.1
  Version (loaded): 5.11.1

CRASH LOG (whole)
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Thread 1 "krita" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50	../sysdeps/unix/sysv/linux/raise.c: Nie ma takiego pliku ani katalogu.
(gdb) bt
#0  0x00007ffff5587ed7 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff5569535 in __GI_abort () at abort.c:79
#2  0x00007ffff57e8911 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff57f438c in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff57f43f7 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff57f46a9 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff57e8522 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007ffff4895a28 in KoPattern::init(QByteArray&) (this=0x555559468d90, bytes=...) at /home/tymon/kritadev/krita/libs/pigment/resources/KoPattern.cpp:207
#8  0x00007ffff4896531 in KoPattern::loadPatFromDevice(QIODevice*) (this=0x555559468d90, dev=0x7fffffffcfc0) at /home/tymon/kritadev/krita/libs/pigment/resources/KoPattern.cpp:81
#9  0x00007ffff489674f in KoPattern::loadFromDevice(QIODevice*, QSharedPointer<KisResourcesInterface>) (this=0x555559468d90, dev=<optimized out>, resourcesInterface=...)
    at /home/tymon/kritadev/krita/libs/pigment/resources/KoPattern.cpp:148
#10 0x00007ffff6bd6fcd in KisFolderStorage::loadVersionedResource(QSharedPointer<KoResource>) (this=0x555557abb7b0, resource=...) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qsharedpointer_impl.h:312
#11 0x00007ffff6bcf634 in KisStoragePlugin::resource(QString const&) (this=0x555557abb7b0, url=...) at /usr/include/c++/8/bits/atomic_base.h:295
#12 0x00007ffff6ba1205 in KisResourceStorage::resource(QString const&) (this=<optimized out>, url=...) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qsharedpointer_impl.h:312
#13 0x00007ffff6b8a16b in KisResourceCacheDb::synchronizeStorage(QSharedPointer<KisResourceStorage>) (storage=...) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qsharedpointer_impl.h:312
#14 0x00007ffff6b9c23e in KisResourceLocator::synchronizeDb() (this=0x555557ad7840) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qsharedpointer_impl.h:330
#15 0x00007ffff6b9ca85 in KisResourceLocator::initialize(QString const&) (this=0x555557ad7840, installationResourcesLocation=...) at /home/tymon/kritadev/krita/libs/resources/KisResourceLocator.cpp:126
#16 0x00007ffff7c33056 in KisApplication::registerResources() (this=0x7fffffffdc60) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qstringbuilder.h:313
#17 0x00007ffff7c35bd7 in KisApplication::start(KisApplicationArguments const&) (this=0x7fffffffdc60, args=...) at /home/tymon/kritadev/krita/libs/ui/KisApplication.cpp:416
#18 0x000055555555d5c0 in main (argc=<optimized out>, argv=<optimized out>) at /home/tymon/kritadev/krita/krita/main.cc:672
#19 0x00007ffff556ab6b in __libc_start_main (main=0x55555555a460 <main>, argc=1, argv=0x7fffffffde48, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffde38) at ../csu/libc-start.c:308
#20 0x000055555555e6ca in _start () at /home/tymon/kritadev/krita/krita/main.cc:493
Comment 1 Bug Janitor Service 2021-10-18 09:24:12 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1104
Comment 2 amyspark 2021-10-20 22:16:10 UTC
Git commit 6a6fd04efb0896cd3342ca630d99ad798e3b443c by L. E. Segovia, on behalf of Halla Rempt.
Committed on 20/10/2021 at 22:15.
Pushed by lsegovia into branch 'master'.

Check whether a .pat file has the right magic number

M  +12   -1    libs/pigment/resources/KoPattern.cpp

https://invent.kde.org/graphics/krita/commit/6a6fd04efb0896cd3342ca630d99ad798e3b443c
Comment 3 amyspark 2021-10-20 22:17:45 UTC
Git commit 96b29ac4f9feb290eeba72a8f06ae06b5c10c7d4 by L. E. Segovia, on behalf of Halla Rempt.
Committed on 20/10/2021 at 22:17.
Pushed by lsegovia into branch 'krita/5.0'.

Check whether a .pat file has the right magic number
(cherry picked from commit 6a6fd04efb0896cd3342ca630d99ad798e3b443c)

M  +12   -1    libs/pigment/resources/KoPattern.cpp

https://invent.kde.org/graphics/krita/commit/96b29ac4f9feb290eeba72a8f06ae06b5c10c7d4