Bug 453165 - Digikam crashes before starting faces detection
Summary: Digikam crashes before starting faces detection
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Preview-RAW (show other bugs)
Version: 7.6.0
Platform: Appimage Linux
: NOR crash
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-28 22:53 UTC by vfrico
Modified: 2022-06-17 05:58 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 7.7.0
Sentry Crash Report:


Attachments
Digikam's log when reproduced the steps (137.66 KB, text/plain)
2022-05-03 07:16 UTC, vfrico
Details
backtrace of my own compilation with the patch (5.57 KB, text/plain)
2022-05-03 22:51 UTC, vfrico
Details
Digikam's log when reproduced the steps (with newer build) (158.17 KB, text/plain)
2022-05-04 17:20 UTC, vfrico
Details
LibRaw patch (646 bytes, patch)
2022-05-05 06:16 UTC, Maik Qualmann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vfrico 2022-04-28 22:53:25 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1. Import a large library of photos. (Some raw file may be present)
2. Let digikam index all the files
3. Click on detect faces process
4. Wait for digikam to crash
5. Start digikam, go straight to detect faces
6. Digikam crashes instantly (just after clicking the button)

OBSERVED RESULT
Digikam crashes instantly

EXPECTED RESULT
Digikam should continue to process the files to search for faces


SOFTWARE/OS VERSIONS
Running this on Ubuntu 20.04 using appimage bundle.

ADDITIONAL INFORMATION.

The terminal shows this message:
```
Digikam::MetaEngine::Private::printExiv2ExceptionError: Cannot load preview data with Exiv2:  (Error # 59 :  "corrupted image metadata"
terminate called after throwing an instance of 'LibRaw_exceptions'
```

I can't identify which file is causing the issue.

I've also experienced the same issue with the debug build. I'm attaching the backtrace of the error. I hope it is fine.

```
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff3341859 in __GI_abort () at abort.c:79
#2  0x00007ffff376d911 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff377938c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff3778369 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff3778d21 in __gxx_personality_v0 () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff3544bef in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#7  0x00007ffff3545281 in _Unwind_RaiseException () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#8  0x00007ffff377969c in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x00007ffff62e1c25 in crxFillBuffer (bitStrm=0x7fff10090600) at /b/dktemp/digikam-v7.6.0/core/libs/rawengine/libraw/src/decoders/crx.cpp:222
#10 0x00007ffff62ee284 in crxFillBuffer (bitStrm=0x7fff10090600) at /b/dktemp/digikam-v7.6.0/core/libs/rawengine/libraw/src/decoders/crx.cpp:1762
#11 crxParamInit (img=img@entry=0x7fff32ffc0d0, param=param@entry=0x7fff28009508, subbandMdatOffset=10486114, subbandDataSize=382166, subbandWidth=787, subbandHeight=1014, supportsPartial=false, roundedBitsMask=0)
    at /b/dktemp/digikam-v7.6.0/core/libs/rawengine/libraw/src/decoders/crx.cpp:1785
#12 0x00007ffff62ee6f7 in crxSetupSubbandData (img=img@entry=0x7fff32ffc0d0, planeComp=planeComp@entry=0x7fff28008738, tile=tile@entry=0x7fff28008620, mdatOffset=<optimized out>)
    at /b/dktemp/digikam-v7.6.0/core/libs/rawengine/libraw/src/decoders/crx.cpp:1912
#13 0x00007ffff62eea14 in LibRaw::crxDecodePlane (p=p@entry=0x7fff32ffc0d0, planeNumber=planeNumber@entry=3, this=<optimized out>) at /b/dktemp/digikam-v7.6.0/core/libs/rawengine/libraw/src/decoders/crx.cpp:1936
#14 0x00007ffff62eec56 in LibRaw::crxDecodePlane (planeNumber=3, p=<optimized out>, this=<optimized out>) at /b/dktemp/digikam-v7.6.0/core/libs/rawengine/libraw/src/decoders/crx.cpp:2703
#15 LibRaw::_ZN6LibRaw17crxLoadDecodeLoopEPvi._omp_fn.0(void) () at /b/dktemp/digikam-v7.6.0/core/libs/rawengine/libraw/src/decoders/crx.cpp:2703
#16 0x00007ffff35657de in gomp_thread_start () from /tmp/.mount_digiKaEdMX3b/usr/lib/libgomp.so.1
#17 0x00007ffff3519609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#18 0x00007ffff343e163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
```
Comment 1 vfrico 2022-04-28 22:58:45 UTC
I've run again the debugger and the stacktrace is different:

```
Thread 53 "Thread (pooled)" hit Breakpoint 1, 0x00007ffff3779660 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#0  0x00007ffff3779660 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x00007fffe87495f5 in ?? () from /tmp/.mount_digiKa7YPQcQ/usr/lib/libexiv2.so.27
#2  0x00007fffe880b5fb in Exiv2::BmffImage::readMetadata() () from /tmp/.mount_digiKa7YPQcQ/usr/lib/libexiv2.so.27
#3  0x00007ffff61f6eb4 in Digikam::MetaEnginePreviews::Private::load (image_=..., this=0x7fff64013670) at /b/dktemp/digikam-v7.6.0/core/libs/metadataengine/engine/metaengine_previews.cpp:71
#4  Digikam::MetaEnginePreviews::MetaEnginePreviews (this=<optimized out>, filePath=...) at /b/dktemp/digikam-v7.6.0/core/libs/metadataengine/engine/metaengine_previews.cpp:130
#5  0x00007ffff628ec28 in Digikam::PreviewLoadingTask::execute (this=0x2ceb2e0) at /b/dktemp/digikam-v7.6.0/core/libs/threadimageio/preview/previewtask.cpp:180
#6  0x00007ffff62a31d9 in Digikam::LoadSaveThread::run (this=0x51712b0) at /b/dktemp/digikam-v7.6.0/core/libs/threadimageio/fileio/loadsavethread.cpp:154
#7  0x00007ffff62d08da in Digikam::DynamicThread::Private::run (this=0x2cf58b0) at /b/dktemp/digikam-v7.6.0/core/libs/threads/dynamicthread.cpp:191
#8  0x00007ffff397fa11 in ?? () from /tmp/.mount_digiKa7YPQcQ/usr/lib/libQt5Core.so.5
#9  0x00007ffff397c819 in ?? () from /tmp/.mount_digiKa7YPQcQ/usr/lib/libQt5Core.so.5
#10 0x00007ffff3519609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#11 0x00007ffff343e163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
```
Comment 2 caulier.gilles 2022-04-29 03:01:29 UTC
Which kind of RAW files did you use exactly ?

Can you provide the console trace (not the debug trace) ?

Gilles Caulier
Comment 3 Maik Qualmann 2022-04-29 06:11:52 UTC
(In reply to vfrico from comment #0)
> Digikam::MetaEngine::Private::printExiv2ExceptionError: Cannot load preview
> data with Exiv2:  (Error # 59 :  "corrupted image metadata"

With this error message it could be an image from a Sony camera. Please test the current developer version digiKam-7.7.0 from here:

https://files.kde.org/digikam/

Maik
Comment 4 vfrico 2022-04-29 08:31:47 UTC
(In reply to caulier.gilles from comment #2)
> Which kind of RAW files did you use exactly ?
> 
> Can you provide the console trace (not the debug trace) ?
> 
> Gilles Caulier

The console trace is specified up. It is:

Digikam::MetaEngine::Private::printExiv2ExceptionError: Cannot load preview data with Exiv2:  (Error # 59 :  "corrupted image metadata"
terminate called after throwing an instance of 'LibRaw_exceptions'


As for the RAW files, the problem is that I don't know which file it can be. I have three Canon camera (350D, 50D [CR2] and M200 [CR3]) and a mobile phone and sometimes I shoot in raw (DMG). The library from which I imported the photos contains about 20k media files. I have no clue which could be the file it is causing the issue.

And I've tested also with the 7.7 version available in nightly channel. The console error is exactly the same.
Comment 5 vfrico 2022-04-29 08:39:19 UTC
It seems that the error may be in this call: https://invent.kde.org/graphics/digikam/-/blob/master/core/libs/metadataengine/engine/metaengine_previews.cpp#L71

I don't have the knowledge to edit the source code (nor to build it) to print here which file is failing. It is possible to someone to submit a patch to have a more detailed error log on the next preview build? Maybe it could be an option to print the file that is causing the program to fail.

Thanks
Comment 6 caulier.gilles 2022-04-29 09:13:16 UTC
We need the completed log from the console, not just the last lines.

Gilles Caulier
Comment 7 caulier.gilles 2022-04-29 09:15:42 UTC
To patch code, just fork digiKam project from KDE git (gitlab in background), make change, and make a merge request.

For simple changes, all can be done through the web interface directly...

https://invent.kde.org/graphics/digikam

Gilles Caulier
Comment 8 Maik Qualmann 2022-04-29 10:38:16 UTC
To see which file is affected enable full debug output in the terminal:

export QT_LOGGING_RULES="digikam.*=true"

Or if there is too much debug output of the libjpeg:

export QT_LOGGING_RULES="digikam.*=true;digikam.dimg.jpeg=false"

Maik
Comment 9 Maik Qualmann 2022-05-02 11:56:33 UTC
Could the file be identified? Can you provide us the file for testing to fix the problem?

Maik
Comment 10 vfrico 2022-05-03 07:16:34 UTC
Created attachment 148527 [details]
Digikam's log when reproduced the steps

I've enabled a more verbose logging to try to get the file that is failing, but I can't see anything.
I promise the log is not modified in any way. The image file just don't show up in the log.
Comment 11 Maik Qualmann 2022-05-03 18:01:56 UTC
Git commit 21b395f696f6d74d1970b5ad82a61e35e4284863 by Maik Qualmann.
Committed on 03/05/2022 at 18:01.
Pushed by mqualmann into branch 'qt5-maintenance'.

add image path to debug output for testing

M  +2    -2    core/libs/rawengine/drawdecoder.cpp

https://invent.kde.org/graphics/digikam/commit/21b395f696f6d74d1970b5ad82a61e35e4284863
Comment 12 vfrico 2022-05-03 22:51:31 UTC
Created attachment 148547 [details]
backtrace of my own compilation with the patch

Thanks for submitting the patch. I've downloaded the code, installed all the needed libraries, compiled the code, but I must have an inadequate exiv2 library, as I am unable to start the program. Find attached the backtrace I get from gdb.

Is any online build available to test the changes? Usually the appimage format runs ok on my system. I don't even know how to generate it.
Comment 13 Maik Qualmann 2022-05-04 05:56:48 UTC
Gilles creates weekly snapshots here:

https://files.kde.org/digikam/

@Gilles, can you please start creating a new AppImage?

Maik
Comment 14 caulier.gilles 2022-05-04 05:59:48 UTC
Sure no problem. It started now. File will be online in few hours

Gilles
Comment 15 Maik Qualmann 2022-05-04 06:27:51 UTC
The cause of your crash in your build is that the digiKam plugins are not found. I tested it on myself and set the environment variable "DK_PLUGIN_PATH" to an empty directory. I can then reproduce the crash, it shouldn't be like that. I will fix it. The plugins were probably not installed in the right place. Did you use the bootstrap.linux script?

Maik
Comment 16 vfrico 2022-05-04 17:20:29 UTC
Created attachment 148562 [details]
Digikam's log when reproduced the steps (with newer build)

I've just downloaded the last .appimage from files.kde.org and yes, the file is now printed correctly. Thanks to Maik and Gilles for being as fast.

Find the complete log in the attatchment, but I think you might find more interesting the files on this dropbox: https://www.dropbox.com/sh/2b60l6rc5da7cff/AACIEsRCLQEkjsfw_DohQYoja?dl=0

I've have had to run multiple times digikam, let it to fail, get the image that is failing and delete it from the digikam library, and then run again the process until it fails again. I've get 23 images failing, but some of them (5) are with people, so I'm not uploading them because I expect the error might be the same.

The camera that is used to produce those images is a Canon M200, with CR3 file. I don't know if it is a problem with the camera itself or it is a problem when copying the files, or a problem on the SD card.

Just FTR: i try to do exiv2 on those CR3 files and shows "corrupted image metadata", but doing the same on other files outputs all the exif information.
Comment 17 Maik Qualmann 2022-05-05 06:16:21 UTC
Created attachment 148570 [details]
LibRaw patch

It clearly crashes in LibRaw. However, your images are probably defective. Please open a bug report on LibRaw with your sample images and a link to this bug report. The cause is an exception in an OpenMP structure block. It is not possible to break out of an OpenMP structured block. The patch in the attachment would solve the problem. Ultimately, however, the LibRaw team must find the correct solution. With this patch you can see a colored line in the images, sometimes there is no error at first glance, sometimes the colors are half wrong, etc. But it no longer leads to a crash.

Maik
Comment 18 caulier.gilles 2022-05-05 06:36:11 UTC
Note to report a UPSTREAM bug in libraw, use github project here :

https://github.com/LibRaw/LibRaw/issues

Don't forget to link to this file to pass technical information to Libraw team.

The current libraw git revision used in digiKam is described in this manifest :

https://invent.kde.org/graphics/digikam/-/blob/master/core/libs/rawengine/libraw/libraw_manifest.txt

Note: Libraw team will not test with digiKam as well, but only with libraw CLI tools. The problem must be reproducible with these CLI tool and libraw settings used by digiKam to process CR3 files. These settings is printed on the console as debug trace when CR3 file is processed.

Thanks in advance

Gilles Caulier
Comment 19 Maik Qualmann 2022-05-09 11:11:05 UTC
We have a patch from the LibRaw team:

https://github.com/LibRaw/LibRaw/issues/460

Maik
Comment 20 Maik Qualmann 2022-06-17 05:58:19 UTC
Crash is now fixed with this commit:

https://invent.kde.org/graphics/digikam/-/commit/65217bee4d6d0600bfd36e3f85bb77314e647b93

Maik