Package: jhead
Version: 1:2.97-1
Severity: normal

Dear Maintainer,

While adjusting some EXIF dates on pictures, the observed change between the 
original picture and the jhead-ed one goes beyond time modifications of the 
corresponding tags.

The default EXIF comment from my camera is a sequence of spaces, which 
translates inside the header to "ASCII\0\0\0                   " (36 spaces 
overall).

This is basically my workflow:
cp -p DSC.JPG DSC_orig.JPG
jhead -ta-1 DSC.JPG
hexdump -Cv DSC_orig.JPG > DSC_orig.txt
hexdump -Cv DSC.JPG > DSC.txt

`diff DSC_orig.txt DSC.txt` returns
17c17
< 00000100  32 3a 32 35 3a 35 35 00  20 20 20 20 20 20 20 20  |2:25:55.        |
---
> 00000100  31 3a 32 35 3a 35 35 00  20 20 20 20 20 20 20 20  |1:25:55.        |
56,57c56,57
< 00000370  3a 31 32 3a 32 35 20 31  32 3a 32 35 3a 35 35 00  |:12:25 12:25:55.|
< 00000380  32 30 31 33 3a 31 32 3a  32 35 20 31 32 3a 32 35  |2013:12:25 12:25|
---
> 00000370  3a 31 32 3a 32 35 20 31  31 3a 32 35 3a 35 35 00  |:12:25 11:25:55.|
> 00000380  32 30 31 33 3a 31 32 3a  32 35 20 31 31 3a 32 35  |2013:12:25 11:25|
60,62c60,62
< 000003b0  00 00 00 0a 41 53 43 49  49 00 00 00 20 20 20 20  |....ASCII...    |
< 000003c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
< 000003d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
---
> 000003b0  00 00 00 0a 41 53 43 49  49 00 00 00 00 00 00 00  |....ASCII.......|
> 000003c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
> 000003d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|


I expect the output to be
17c17
< 00000100  32 3a 32 35 3a 35 35 00  20 20 20 20 20 20 20 20  |2:25:55.        |
---
> 00000100  31 3a 32 35 3a 35 35 00  20 20 20 20 20 20 20 20  |1:25:55.        |
56,57c56,57
< 00000370  3a 31 32 3a 32 35 20 31  32 3a 32 35 3a 35 35 00  |:12:25 12:25:55.|
< 00000380  32 30 31 33 3a 31 32 3a  32 35 20 31 32 3a 32 35  |2013:12:25 12:25|
---
> 00000370  3a 31 32 3a 32 35 20 31  31 3a 32 35 3a 35 35 00  |:12:25 11:25:55.|
> 00000380  32 30 31 33 3a 31 32 3a  32 35 20 31 31 3a 32 35  |2013:12:25 11:25|


I tracked the issue down to exif.c where the code takes conditional actions on 
the comment field. It will remove trailing spaces and replace them with \0, 
then conditionnally copy the comment if one of the five first characters after 
the 'ASCII' string is different from a space of \0.

I expect this situation to lead to a corner case bug (untested): a comment 
starting with several spaces will be wiped when adjusting time.

I also think this happens upon creation of the modified file and is likely not 
limited to the -ta option.

The issue is not Debian specific but in the upstream code. A patch is attached 
to suggest a more conservative behaviour of jhead.

Thank you
--
Sylvain

-- System Information:
Debian Release: jessie/sid
  APT prefers testing
  APT policy: (990, 'testing'), (50, 'unstable'), (40, 'experimental')
Architecture: armel (armv5tel)

Kernel: Linux 3.11-2-kirkwood
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages jhead depends on:
ii  libc6          2.17-97
ii  libjpeg-progs  8d-2

jhead recommends no packages.

Versions of packages jhead suggests:
ii  imagemagick  8:6.7.7.10-7

-- no debconf information
diff -ru jhead.orig/jhead-2.97/exif.c jhead/jhead-2.97/exif.c
--- jhead.orig/jhead-2.97/exif.c	2013-01-30 18:02:56.000000000 +0100
+++ jhead/jhead-2.97/exif.c	2013-12-30 12:16:47.037757973 +0100
@@ -663,33 +663,12 @@
                     break; // Already have a windows comment, skip this one.
                 }
 
-                // Comment is often padded with trailing spaces.  Remove these first.
-                for (a=ByteCount;;){
-                    a--;
-                    if ((ValuePtr)[a] == ' '){
-                        (ValuePtr)[a] = '\0';
-                    }else{
-                        break;
-                    }
-                    if (a == 0) break;
-                }
-
                 // Copy the comment
                 {
                     int msiz = ExifLength - (ValuePtr-OffsetBase);
                     if (msiz > ByteCount) msiz = ByteCount;
                     if (msiz > MAX_COMMENT_SIZE-1) msiz = MAX_COMMENT_SIZE-1;
-                    if (msiz > 5 && memcmp(ValuePtr, "ASCII",5) == 0){
-                        for (a=5;a<10 && a < msiz;a++){
-                            int c = (ValuePtr)[a];
-                            if (c != '\0' && c != ' '){
-                                strncpy(ImageInfo.Comments, (char *)ValuePtr+a, msiz-a);
-                                break;
-                            }
-                        }
-                    }else{
-                        strncpy(ImageInfo.Comments, (char *)ValuePtr, msiz);
-                    }
+                    strncpy(ImageInfo.Comments, (char *)ValuePtr, msiz);
                 }
                 break;
 

Reply via email to