adobe / XMP-Toolkit-SDK

The XMP Toolkit allows you to integrate XMP functionality into your product or solution
BSD 3-Clause "New" or "Revised" License
205 stars 83 forks source link

Exif Date missing seconds values #50

Closed lmartin closed 1 year ago

lmartin commented 3 years ago

I started from SDK code in "samples/source/ModifyingXMP.cpp". I just extract XMP metadata from my photo source and reinject it in my new photo. Fields "Create Date" and "Date/Time Original" are missing seconds values. Here are the values I get when inspecting metadata with exiftool command line:

Photo source: Create Date : 2021:07:25 12:00:00 Date/Time Original : 2021:07:25 12:00:00

New photo: Create Date : 2021:07:25 12:00 Date/Time Original : 2021:07:25 12:00:

Priyanka-Gupta commented 2 years ago

Thanks for reporting it. Could you please try with the latest release and if the issue still persists, please share the sample test file and the code snippet which you are using.

jerry-skydio commented 2 years ago

We've found the same issue and discovered it to be related to this code. Here is a possible patch to fix

index d8dc1daa576..6d4adba85e1 100644
--- a/XMPFiles/source/FormatSupport/ReconcileTIFF.cpp
+++ b/XMPFiles/source/FormatSupport/ReconcileTIFF.cpp
@@ -2706,47 +2706,15 @@ ExportTIFF_Date ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp

                char buffer[24];
                snprintf ( buffer, sizeof(buffer), "%04d:%02d:%02d %02d:%02d:%02d",     // AUDIT: Use of sizeof(buffer) is safe.
                                   xmpBin.year, xmpBin.month, xmpBin.day, xmpBin.hour, xmpBin.minute, xmpBin.second );

                char buffer[24];
                snprintf ( buffer, sizeof(buffer), "%04d:%02d:%02d %02d:%02d:%02d",     // AUDIT: Use of sizeof(buff
er) is safe.
                                   xmpBin.year, xmpBin.month, xmpBin.day, xmpBin.hour, xmpBin.minute, xmpBin.second 
);

-               size_t xmpLen = xmpStr.size();
-               if ( xmpLen < 18 ) {
-                       buffer[17] = buffer[18] = ' ';
-                       if ( xmpLen < 15 ) {
-                               buffer[14] = buffer[15] = ' ';
-                               if ( xmpLen < 12 ) {
-                                       buffer[11] = buffer[12] = ' ';
-                                       if ( xmpLen < 9 ) {
-                                               buffer[8] = buffer[9] = ' ';
-                                               if ( xmpLen < 6 ) {
-                                                       buffer[5] = buffer[6] = ' ';
-                                                       if ( xmpLen < 1 ) {
-                                                               buffer[0] = buffer[1] = buffer[2] = buffer[3] = ' ';
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-               
                tiff->SetTag_ASCII ( mainIFD, mainID, buffer );

-               if ( xmpBin.nanoSecond == 0 ) {
-               
-                       tiff->DeleteTag ( kTIFF_ExifIFD, fracID );
-               
-               } else {
+               snprintf ( buffer, sizeof(buffer), "%09d", xmpBin.nanoSecond ); // AUDIT: Use of sizeof(buffer) is safe.

-                       snprintf ( buffer, sizeof(buffer), "%09d", xmpBin.nanoSecond ); // AUDIT: Use of sizeof(buffer) is safe.
-                       for ( size_t i = strlen(buffer)-1; i > 0; --i ) {
-                               if ( buffer[i] != '0' ) break;
-                               buffer[i] = 0;  // Strip trailing zero digits.
-                       }
-
-                       tiff->SetTag_ASCII ( kTIFF_ExifIFD, fracID, buffer );   // ! The subseconds are always in the Exif IFD.
-
-               }
+               tiff->SetTag_ASCII ( kTIFF_ExifIFD, fracID, buffer );   // ! The subseconds are always in the Exif IFD.

        } catch ( ... ) {
                // Do nothing, let other exports proceed.
                // ? Notify client?
        }

We don't have the context on the original code though. Can someone expand on why it was stripping trailing values, or why xmpStr was reading out with missing zeroes?

LidiaMirkin commented 2 years ago

Hello

We have the same issue. Last version in git does not contain the fix. ORIGINAL And Result files are attached. ORIGINAL : 1.jpg Result: 2.jpg Broken fields: Date TimeOriginal 1 2

maupadhyay commented 1 year ago

Fixed with July 2023 release