Package: ruby-prawn
Version: 1.3.0
Severity: wishlist
Tags: patch
User: reproducible-bui...@lists.alioth.debian.org
Usertags: toolchain randomness

Hi!

While working on the “reproducible builds” effort [1], we have noticed
that Prawn is generating PDF with undeterministic keys for gradients.

With the attached patch, Prawn will use an internal Hash with an
incremental index starting at 1 instead of the undetermistic #hash
method for gradient keys.

 [1]: https://wiki.debian.org/ReproducibleBuilds

-- 
Lunar                                .''`. 
lu...@debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
From 43eb75dc02b386c32c876164c74d326911a7f0f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Bobbio?= <lu...@debian.org>
Date: Sun, 19 Apr 2015 16:03:41 +0200
Subject: [PATCH 1/2] Use deterministic keys for gradients

Add 0700_use_deterministic_keys_for_gradients.patch to make
Prawn build PDF in a deterministic manner when they use gradients.
---
 debian/changelog                                   |  7 ++++
 ...0700_use_deterministic_keys_for_gradients.patch | 40 ++++++++++++++++++++++
 debian/patches/series                              |  1 +
 3 files changed, 48 insertions(+)
 create mode 100644 debian/patches/0700_use_deterministic_keys_for_gradients.patch

diff --git a/debian/changelog b/debian/changelog
index 07178a4..eef987e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+ruby-prawn (1.3.0+dfsg-1.0~reproducible1) UNRELEASED; urgency=low
+
+  * Add 0700_use_deterministic_keys_for_gradients.patch to make
+    Prawn build PDF in a deterministic manner when they use gradients.
+
+ -- Jérémy Bobbio <lu...@debian.org>  Sun, 19 Apr 2015 14:25:51 +0200
+
 ruby-prawn (1.3.0+dfsg-1) unstable; urgency=medium
 
   * Imported Upstream version 1.3.0+dfsg
diff --git a/debian/patches/0700_use_deterministic_keys_for_gradients.patch b/debian/patches/0700_use_deterministic_keys_for_gradients.patch
new file mode 100644
index 0000000..c198848
--- /dev/null
+++ b/debian/patches/0700_use_deterministic_keys_for_gradients.patch
@@ -0,0 +1,40 @@
+Description: Use deterministic values for gradients
+ Previously, Prawn used #hash for gradients. Unfortunately, this uses
+ #object_id internally and prevent Prawn to create PDF using gradients
+ in a reproducible manner.
+ .
+ We now instead use an internal Hash with an incremental index starting
+ at 1.
+Author: Jérémy Bobbio <lu...@debian.org>
+
+Index: git/lib/prawn/graphics/patterns.rb
+===================================================================
+--- git.orig/lib/prawn/graphics/patterns.rb	2015-04-19 15:15:52.112246285 +0200
++++ git/lib/prawn/graphics/patterns.rb	2015-04-19 15:47:30.755127617 +0200
+@@ -60,7 +60,7 @@
+       end
+ 
+       def gradient_registry_key(gradient)
+-        if gradient[1].is_a?(Array) # axial
++        key = if gradient[1].is_a?(Array) # axial
+           [
+             map_to_absolute(gradient[0]),
+             map_to_absolute(gradient[1]),
+@@ -74,7 +74,16 @@
+             gradient[3],
+             gradient[4], gradient[5]
+           ]
+-        end.hash
++        end
++        unless @gradient_key_registry
++          @gradient_key_registry ||= {}
++          @gradient_key_index = 1
++        end
++        unless @gradient_key_registry.include?(key)
++          @gradient_key_registry[key] = @gradient_key_index
++          @gradient_key_index += 1
++        end
++        @gradient_key_registry[key]
+       end
+ 
+       def gradient_registry
diff --git a/debian/patches/series b/debian/patches/series
index 9be8a9d..3ddcfe4 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -5,3 +5,4 @@
 0405_use_system_fonts_manual.patch
 0500_disable_tests_using_removed_files.patch
 0600_replace_require_relative_manual.patch
+0700_use_deterministic_keys_for_gradients.patch
-- 
1.9.1

Attachment: signature.asc
Description: Digital signature

Reply via email to