Bug 434246

Summary: XMP metadata fails to write to file with Exiv2 - Use ExifTool instead.
Product: [Applications] digikam Reporter: michael.c.brown1
Component: Metadata-XmpAssignee: Digikam Developers <digikam-bugs-null>
Severity: normal CC: caulier.gilles, metzpinguin
Priority: NOR    
Version: 7.2.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In: 8.0.0
Sentry Crash Report:
Attachments: Test file which reproduces XMP data fail to write

Description michael.c.brown1 2021-03-10 17:11:37 UTC
Created attachment 136559 [details]
Test file which reproduces XMP data fail to write

XMP metadata is failing to write to a file. Based on testing, this appears to be caused by corrupted existing face data (mwg-rs) already in the file. digiKam does not provide any error message to let the user know there is an issue.

1. Load the attached file in digiKam
2. Read existing metadata (Item > Reread metadata from file)
3. Add new face tag data 
4. Write metadata to file (Item > Write metadata to file)
5. Check the metadata of the file

New face tag data is not written to the file as expected.

File would contain newly added face tag metadata.

Windows: 10.0.19042 Build 19042 (Microsoft Windows 10 Pro)
digiKam version: 7.2.0-rc

I believe this is caused by corrupted existing face data already in the file under the "mwg-rs" XMP tag. I can resolve the error by removing mwg-rs metadata using the 3rd-party tool exiftool, then rewriting the face tag data in digiKam.
Note: I recently upgraded from digiKam 6.4 to 7.2.0-rc. I am unclear if this upgrade introduced the corrupted XMP data.
Comment 1 Maik Qualmann 2021-03-11 07:00:35 UTC

*** This bug has been marked as a duplicate of bug 220204 ***
Comment 2 michael.c.brown1 2021-03-11 09:21:37 UTC
Hi Maik,
Thanks for your review, but I disagree with this being considered a duplicate of 220204. Issue 220204 seems to be related to permissions (read-only file, protected directory, etc.) whereas 434246 is related specifically to mwg-rs causing issues. Note the attachment I provided to recreate issue 434246 is not read-only. 

Warning the user is a similar desirable piece of this, but I believe the root cause of 434246 (why metadata write fails) to be a different, separate issue.
Comment 3 Maik Qualmann 2021-03-11 09:39:28 UTC
The problem is more general. Regardless of whether it is write-protected or, as with your image, Exiv2 a toolkit error 102 reported. There is no warning from digiKam to the user. Error 102 is also reported by users in Darktable, which program is causing it is unknown. I don't think Exiv2 is causing it. The images with the problem mostly come from Windows users. I don't like flooding the system messages or always showing a popup when Exiv2 encounters an error. It would be too much. In the event of a write error in the metadata, I am considering making a property entry in the database so that problematic images can be searched for and displayed - just an idea at the moment.

Comment 4 michael.c.brown1 2021-03-11 11:15:45 UTC
I see, thank you for the further explanation. For what it’s worth, as a user, I would definitely want to know of such errors. I have spent hundreds of hours meticulously tagging each photo, only the find the data was not saving as expected. I write to file metadata because I don’t want my tags to only work in digiKam, I want them to work in any future application I may choose. Now due to this issue, I need to perform a clunky workaround using 3rd party software on my entire collection because I don’t know which photos are affected and which are not. I am finding many more are affected than I originally thought, leading me to believe this XMP corruption/error is actually introduced digiKam itself (possibly in transition from 6.4 > 7.2 but I am not sure about this).
Comment 5 Maik Qualmann 2021-03-11 12:16:13 UTC
I checked again, the Toolkit 102 error may be related to images from Apple devices. Exiv2 also reports an unknown namespace "apple-fi" in your image. Similar problems were also reported with Gimp. If the problem can be reproduced with an image that has not yet been edited with Exiv2 and the problem can be repeated with the Exiv2 CLI tool, you should report the problem to Exiv2.

Comment 6 michael.c.brown1 2021-03-11 16:49:28 UTC
I can confirm that this is not isolated to Apple photos as I have the same error on photos taken with my Canon camera. I have only used digiKam for my face tagging, so I am not sure how to test only Exiv2 as you suggest.
Comment 7 michael.c.brown1 2021-03-12 13:55:26 UTC
I think I've finally figured this out. I was incorrect thinking I saw this on my Canon camera, the errors are only occurring on photos from our iPhones. I found a clean photo that I never entered into digiKam and there was already facial data saved. Apple must have embedded facial recognition technology in their software that automatically writes the facial region to the XMP metadata. Any photo that has this data already saved, digiKam cannot write to. Damn Apple.

Does this mean the inability to write metadata is isolated to Exiv2? If so, I can file a bug report over there as well. It would of course still be nice if digiKam had notified of the inability to write the new facial data I applied (as already captured in bug 220204). Thank you.
Comment 8 caulier.gilles 2022-04-10 05:14:40 UTC
Fixed with the new support of ExifTool to write metadata in place of Exiv2.