Source: imagemagick
Version: 8:6.8.9.9-7
Severity: wishlist
Tags: patch
User: reproducible-builds@lists.alioth.debian.org
Usertags: toolchain timestamps
X-Debbugs-Cc: reproducible-builds@lists.alioth.debian.org

Hi!

While working on the "reproducible builds" effort [1], we have noticed
that imagemagick embeds the current time/date when converting images
into PDF files (CreationDate / ModDate in metadata).

The attached patch adds support for the SOURCE_DATE_EPOCH environmeht
variable [2] to replace the timestamp with a deterministic one.

Regards,
 Reiner

[1]: https://wiki.debian.org/ReproducibleBuilds
[2]: https://reproducible-builds.org/specs/source-date-epoch/
diff --git a/debian/patches/0078-Honour-source-date-epoch.patch b/debian/patches/0078-Honour-source-date-epoch.patch
new file mode 100644
index 0000000..8283df4
--- /dev/null
+++ b/debian/patches/0078-Honour-source-date-epoch.patch
@@ -0,0 +1,46 @@
+Author: Reiner Herrmann <rei...@reiner-h.de>
+Description: Honour SOURCE_DATE_EPOCH for PDF timestamp
+ When the environment variable SOURCE_DATE_EPOCH is defined, its timestamp
+ is used instead of the current time for timestamps embedded into PDF
+ metadata.
+ .
+ See also: https://reproducible-builds.org/specs/source-date-epoch/
+
+--- a/coders/pdf.c
++++ b/coders/pdf.c
+@@ -2669,12 +2669,32 @@
+   (void) FormatLocaleString(buffer,MaxTextExtent,"/Title (%s)\n",
+     EscapeParenthesis(basename));
+   (void) WriteBlobString(image,buffer);
+-  seconds=time((time_t *) NULL);
++  char *source_date_epoch;
++  source_date_epoch = getenv("SOURCE_DATE_EPOCH");
++  if (source_date_epoch) {
++    char *endptr;
++    seconds = strtoull(source_date_epoch, &endptr, 10);
++    if ((errno == ERANGE && seconds == ULLONG_MAX)
++       || (errno != 0 && seconds == 0)
++       || (endptr == source_date_epoch)
++       || (*endptr != '\0')
++       || (seconds > ULONG_MAX)) {
++      (void) CloseBlob(image);
++      return(MagickFalse);
++    }
++#if defined(MAGICKCORE_HAVE_GMTIME_R)
++    (void) gmtime_r(&seconds,&local_time);
++#else
++    (void) memcpy(&local_time,gmtime(&seconds),sizeof(local_time));
++#endif
++  } else {
++    seconds=time((time_t *) NULL);
+ #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
+-  (void) localtime_r(&seconds,&local_time);
++    (void) localtime_r(&seconds,&local_time);
+ #else
+-  (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
++    (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
+ #endif
++  }
+   (void) FormatLocaleString(date,MaxTextExtent,"D:%04d%02d%02d%02d%02d%02d",
+     local_time.tm_year+1900,local_time.tm_mon+1,local_time.tm_mday,
+     local_time.tm_hour,local_time.tm_min,local_time.tm_sec);
diff --git a/debian/patches/series b/debian/patches/series
index cc6a025..871c591 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -74,3 +74,4 @@
 0073-Fixed-memory-leaks.patch
 0074-Fix-overflow-in-pict-image-parsing.patch
 0075-Fix-buffer-overflow-in-icon-parsing-code.patch
+0078-Honour-source-date-epoch.patch

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to