Bug 148182 - Iptc.Application2.Keywords appends always the 0-byte
Summary: Iptc.Application2.Keywords appends always the 0-byte
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Metadata-Iptc (show other bugs)
Version: unspecified
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-25 02:00 UTC by oongi
Modified: 2022-01-08 13:45 UTC (History)
3 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description oongi 2007-07-25 02:00:08 UTC
Version:           0.9.2 (using KDE KDE 3.5.5)
Installed from:    Debian stable Packages
Compiler:          gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) 
OS:                Linux

digikam 0.9.2 always appends to all Iptc.Application2.Keywords Tags the 0-byte (0x00), as one can see with exiv2:

name@linux:~$ exiv2 -p i pr testimg.jpg | hexdump -C
00000000  49 70 74 63 2e 41 70 70  6c 69 63 61 74 69 6f 6e  |Iptc.Application|
00000010  32 2e 50 72 6f 67 72 61  6d 20 20 20 20 20 20 20  |2.Program       |
00000020  20 20 20 20 20 20 20 20  20 20 20 20 20 53 74 72  |             Str|
00000030  69 6e 67 20 20 20 20 20  34 36 20 20 64 69 67 69  |ing     46  digi|
00000040  6b 61 6d 20 28 55 73 69  6e 67 20 4b 69 70 69 20  |kam (Using Kipi |
00000050  4d 65 74 61 64 61 74 61  45 64 69 74 20 70 6c 75  |MetadataEdit plu|
00000060  67 69 6e 20 30 2e 31 2e  34 29 0a 49 70 74 63 2e  |gin 0.1.4).Iptc.|
00000070  41 70 70 6c 69 63 61 74  69 6f 6e 32 2e 50 72 6f  |Application2.Pro|
00000080  67 72 61 6d 56 65 72 73  69 6f 6e 20 20 20 20 20  |gramVersion     |
00000090  20 20 20 20 20 20 20 20  53 74 72 69 6e 67 20 20  |        String  |
000000a0  20 20 20 31 31 20 20 30  2e 39 2e 32 2d 66 69 6e  |   11  0.9.2-fin|
000000b0  61 6c 0a 49 70 74 63 2e  41 70 70 6c 69 63 61 74  |al.Iptc.Applicat|
000000c0  69 6f 6e 32 2e 55 72 67  65 6e 63 79 20 20 20 20  |ion2.Urgency    |
000000d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000000e0  53 74 72 69 6e 67 20 20  20 20 20 20 31 20 20 38  |String      1  8|
000000f0  0a 49 70 74 63 2e 41 70  70 6c 69 63 61 74 69 6f  |.Iptc.Applicatio|
00000100  6e 32 2e 42 79 6c 69 6e  65 54 69 74 6c 65 20 20  |n2.BylineTitle  |
00000110  20 20 20 20 20 20 20 20  20 20 20 20 20 20 53 74  |              St|
00000120  72 69 6e 67 20 20 20 20  20 20 30 20 20 0a 49 70  |ring      0  .Ip|
00000130  74 63 2e 41 70 70 6c 69  63 61 74 69 6f 6e 32 2e  |tc.Application2.|
00000140  42 79 6c 69 6e 65 20 20  20 20 20 20 20 20 20 20  |Byline          |
00000150  20 20 20 20 20 20 20 20  20 20 20 53 74 72 69 6e  |           Strin|
00000160  67 20 20 20 20 20 20 34  20 20 74 65 73 74 0a 49  |g      4  test.I|
00000170  70 74 63 2e 41 70 70 6c  69 63 61 74 69 6f 6e 32  |ptc.Application2|
00000180  2e 4b 65 79 77 6f 72 64  73 20 20 20 20 20 20 20  |.Keywords       |
00000190  20 20 20 20 20 20 20 20  20 20 20 20 53 74 72 69  |            Stri|
000001a0  6e 67 20 20 20 20 20 20  35 20 20 74 65 73 74 00  |ng      5  test.|
000001b0  0a                                                |.|

It make no difference wheter I use the tag-feature to put "test" in the IPTC-field or "Picture->Metadata->Edit IPTC". Note, that only to the "Keywords"-Tags the 0-byte is appended, not to the other IPTC-Tags.

Is there a workaround? This way I can't export the images to gallery2...

Thanks

oongi
Comment 1 giaracca 2007-09-01 07:50:24 UTC
I confirm this bug also for digikam 0.9.1
If I import to gallery an image with multiple keywords only the first one is inserted into the database due to the null char.
For know I have patched gallery, but I think that is a digikam bug.
See https://sourceforge.net/tracker/index.php?func=detail&aid=1785206&group_id=7130&atid=107130
Thanks,

      gianpaolo
Comment 2 caulier.gilles 2007-09-01 09:31:42 UTC
Andreas,

Are you seen this file ? What do you think about ?

Gilles
Comment 3 Andreas Huggel 2007-09-01 10:30:57 UTC
I can't reproduce that with a simple test:

ahuggel@mowgli> exiv2 -M'set Iptc.Application2.Keywords DIGIKAM' exiv2-empty.jpg 
ahuggel@mowgli> ./exiv2 -pi exiv2-empty.jpg | hexdump -C
00000000  49 70 74 63 2e 41 70 70  6c 69 63 61 74 69 6f 6e  |Iptc.Application|
00000010  32 2e 4b 65 79 77 6f 72  64 73 20 20 20 20 20 20  |2.Keywords      |
00000020  20 20 20 20 20 20 20 20  20 20 20 20 20 53 74 72  |             Str|
00000030  69 6e 67 20 20 20 20 20  20 37 20 20 44 49 47 49  |ing      7  DIGI|
00000040  4b 41 4d 0a                                       |KAM.|
00000044

Where is the code in digikam which sets the keywords?

-ahu.
Comment 4 caulier.gilles 2007-09-01 10:47:31 UTC
Andreas,

The code is in libkexiv2 :

http://websvn.kde.org/branches/extragear/kde3/libs/libkexiv2/libkexiv2/kexiv2.cpp?revision=704515&view=markup

Look method "bool KExiv2::setImageKeywords(...)"

Gilles
Comment 5 oongi 2007-09-01 11:42:28 UTC
@Andreas:

in your test, you set the Keywords with exiv2 instead of digikam. Setting keywords with exiv2 works here fine, too. I only used exiv2 to display the NULL-Byte appended by digikam.

If you want to reproduce, you have to use digikam to set the keyword.

Thanks

oongi
Comment 6 Andreas Huggel 2007-09-01 11:48:07 UTC
oongi:

yes, my job is to test if the problem is with exiv2 :)

-ahu.
Comment 7 oongi 2007-09-01 11:56:31 UTC
sorry, didn't understand that...

bye

oongi
Comment 8 Andreas Huggel 2007-09-01 12:16:44 UTC
Gilles:

Use a string value instead of an asciiString. Exiv2::AsciiValue adds a 0-byte (which is required for Exif strings). Just change 'asciiString' to 'string' in the first of these 3 lines in KExiv2::setImageKeywords:

 Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::asciiString);
 val->read(key.latin1());
 iptcData.add(iptcTag, val.get());

The same fix is needed in all other places where an IPTC string tag is set. I saw similar code in KExiv2::setImageSubjects and KExiv2::setImageSubCategories.

oongi:

Sorry, should have elaborated: digikam uses exiv2 (the library) to deal with Exif and IPTC metadata. When there is such a problem, it may be a bug for digikam or for exiv2. Since I'm an exiv2 developer, I need to know whether it is an exiv2 bug and a quick way to test for this is to reproduce the problem with the exiv2 utility.

-ahu.
Comment 9 caulier.gilles 2007-09-01 12:38:04 UTC
Thanks Andreas,

I will fix it

Gilles
Comment 10 caulier.gilles 2007-09-01 12:42:24 UTC
oongi,

Can you try to patch the code in libKexiv2 (KExiv2::setImageKeywords() method) to validate the fix with digiKam. Thanks in advance

Gilles
Comment 11 caulier.gilles 2007-09-01 12:46:37 UTC
SVN commit 707242 by cgilles:

libkexiv2 from KDE3 branch : fix IPTC strings creation with non-zero value at end
CCBUGS: 148182


 M  +3 -3      kexiv2.cpp  


--- branches/extragear/kde3/libs/libkexiv2/libkexiv2/kexiv2.cpp #707241:707242
@@ -2042,7 +2042,7 @@
             QString key = *it;
             key.truncate(64);
             
-            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::asciiString);
+            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
             val->read(key.latin1());
             iptcData.add(iptcTag, val.get());        
         }
@@ -2125,7 +2125,7 @@
             QString key = *it;
             key.truncate(236);
             
-            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::asciiString);
+            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
             val->read(key.latin1());
             iptcData.add(iptcTag, val.get());        
         }
@@ -2209,7 +2209,7 @@
             QString key = *it;
             key.truncate(32);
             
-            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::asciiString);
+            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
             val->read(key.latin1());
             iptcData.add(iptcTag, val.get());        
         }
Comment 12 caulier.gilles 2007-09-01 12:48:58 UTC
Angelo,

Patch given on #11 must be backported to Mandriva 2008.0 package...

Gilles
Comment 13 caulier.gilles 2007-09-01 12:51:16 UTC
SVN commit 707247 by cgilles:

libkexiv2 from trunk (KDE4) : fix IPTC strings creation with non-zero value at end
BUG: 148182


 M  +3 -3      kexiv2.cpp  


--- trunk/extragear/libs/libkexiv2/libkexiv2/kexiv2.cpp #707246:707247
@@ -2565,7 +2565,7 @@
             QString key = *it;
             key.truncate(64);
             
-            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::asciiString);
+            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
             val->read(key.toLatin1().constData());
             iptcData.add(iptcTag, val.get());        
         }
@@ -2648,7 +2648,7 @@
             QString key = *it;
             key.truncate(236);
             
-            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::asciiString);
+            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
             val->read(key.toLatin1().constData());
             iptcData.add(iptcTag, val.get());        
         }
@@ -2732,7 +2732,7 @@
             QString key = *it;
             key.truncate(32);
             
-            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::asciiString);
+            Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
             val->read(key.toLatin1().constData());
             iptcData.add(iptcTag, val.get());        
         }
Comment 14 Angelo Naselli 2007-09-01 13:44:31 UTC
Gilles, how about releasing a new versione instead?
Comment 15 caulier.gilles 2007-09-01 13:55:40 UTC
Angelo,

Yes, releasing a new version is fine for me. 3 B.K.O files have been fixed + few API improvements.

You decide to do it. If you have free time, feel free to do it...

Gilles
Comment 16 oongi 2007-09-02 14:14:53 UTC
I don't know how to patch the code witch patch, instead I changed in the lines 2022, 2105 and 2189 of kexiv2.cpp (version 0.1.5 of libkexiv2) "Exiv2::asciiString" in "Exiv2::string" and now there isn't the NULL-Byte at the end of the tags:

name@linux:~$ exiv2 -pi  testimg.jpg | hexdump -C
00000000  49 70 74 63 2e 41 70 70  6c 69 63 61 74 69 6f 6e  |Iptc.Application|
00000010  32 2e 4b 65 79 77 6f 72  64 73 20 20 20 20 20 20  |2.Keywords      |
00000020  20 20 20 20 20 20 20 20  20 20 20 20 20 53 74 72  |             Str|
00000030  69 6e 67 20 20 20 20 20  20 34 20 20 74 65 73 74  |ing      4  test|
00000040  0a 49 70 74 63 2e 41 70  70 6c 69 63 61 74 69 6f  |.Iptc.Applicatio|
00000050  6e 32 2e 50 72 6f 67 72  61 6d 20 20 20 20 20 20  |n2.Program      |
00000060  20 20 20 20 20 20 20 20  20 20 20 20 20 20 53 74  |              St|
00000070  72 69 6e 67 20 20 20 20  20 34 36 20 20 64 69 67  |ring     46  dig|
00000080  69 6b 61 6d 20 28 55 73  69 6e 67 20 4b 69 70 69  |ikam (Using Kipi|
00000090  20 4d 65 74 61 64 61 74  61 45 64 69 74 20 70 6c  | MetadataEdit pl|
000000a0  75 67 69 6e 20 30 2e 31  2e 34 29 0a 49 70 74 63  |ugin 0.1.4).Iptc|
000000b0  2e 41 70 70 6c 69 63 61  74 69 6f 6e 32 2e 50 72  |.Application2.Pr|
000000c0  6f 67 72 61 6d 56 65 72  73 69 6f 6e 20 20 20 20  |ogramVersion    |
000000d0  20 20 20 20 20 20 20 20  20 53 74 72 69 6e 67 20  |         String |
000000e0  20 20 20 20 31 31 20 20  30 2e 39 2e 32 2d 66 69  |    11  0.9.2-fi|
000000f0  6e 61 6c 0a                                       |nal.|

Thanks a lot!

oongi

P.S. and now move on to the next one: https://bugs.kde.org/show_bug.cgi?id=149475 ;-)
Comment 17 Arnd Baecker 2007-09-02 14:24:41 UTC
To apply a patch just do
  patch < patchfile.patch
in the right directory. Sometimes
  patch -p0 < patchfile.patch
is needed (I always forget when, but patch will tell you ... ;-),

To provide a patch just do
  svn diff > patchfile.patch

Best, Arnd