Panu Matilainen 8fcb96
commit 61b41cd3d9f2003cbfd7c987f35fc6aedddd2a73
Panu Matilainen 8fcb96
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 8fcb96
Date:   Fri Jan 13 10:48:43 2017 +0200
Panu Matilainen 8fcb96
Panu Matilainen 8fcb96
    Make the signature header size constant between 32- and 64-bit tags
Panu Matilainen 8fcb96
    
Panu Matilainen 8fcb96
    Since commit 68bddc353a7ea87ea00ad957858cd509e845e84c we're initially
Panu Matilainen 8fcb96
    creating the signature header with estimated values, and if you're
Panu Matilainen 8fcb96
    unlucky enough to have the estimated and actual size on the different
Panu Matilainen 8fcb96
    sides of UINT32_MAX boundary, the resulting package will have the main
Panu Matilainen 8fcb96
    header off by eight bytes, making it unreadable by rpm (RhBug:1405570)
Panu Matilainen 8fcb96
    
Panu Matilainen 8fcb96
    Always reserve a little bit of space in the signature header so we
Panu Matilainen 8fcb96
    we can maintain the overall size constant regardless of whether 32- or
Panu Matilainen 8fcb96
    64-bit tags were used by using a smaller "padding" with 64bit tags.
Panu Matilainen 8fcb96
    
Panu Matilainen 8fcb96
    (cherry picked from commit e51644e0ee2d33c02c06560f87ea6aecb9991673)
Panu Matilainen 8fcb96
Panu Matilainen 8fcb96
diff --git a/lib/signature.c b/lib/signature.c
Panu Matilainen 8fcb96
index 9784c7b..1b9fe34 100644
Panu Matilainen 8fcb96
--- a/lib/signature.c
Panu Matilainen 8fcb96
+++ b/lib/signature.c
Panu Matilainen 8fcb96
@@ -304,7 +304,8 @@ rpmRC rpmGenerateSignature(char *SHA1, uint8_t *MD5, rpm_loff_t size,
Panu Matilainen 8fcb96
     struct rpmtd_s td;
Panu Matilainen 8fcb96
     rpmRC rc = RPMRC_OK;
Panu Matilainen 8fcb96
     char *reservedSpace;
Panu Matilainen 8fcb96
-    int spaceSize = 0;
Panu Matilainen 8fcb96
+    int spaceSize = 32; /* always reserve a bit of space */
Panu Matilainen 8fcb96
+    int gpgSize = rpmExpandNumeric("%{__gpg_reserved_space}");
Panu Matilainen 8fcb96
 
Panu Matilainen 8fcb96
     /* Prepare signature */
Panu Matilainen 8fcb96
     sig = rpmNewSignature();
Panu Matilainen 8fcb96
@@ -349,9 +350,14 @@ rpmRC rpmGenerateSignature(char *SHA1, uint8_t *MD5, rpm_loff_t size,
Panu Matilainen 8fcb96
 	td.tag = RPMSIGTAG_LONGSIZE;
Panu Matilainen 8fcb96
 	td.data = &s;
Panu Matilainen 8fcb96
 	headerPut(sig, &td, HEADERPUT_DEFAULT);
Panu Matilainen 8fcb96
+
Panu Matilainen 8fcb96
+	/* adjust for the size difference between 64- and 32bit tags */
Panu Matilainen 8fcb96
+	spaceSize -= 8;
Panu Matilainen 8fcb96
     }
Panu Matilainen 8fcb96
 
Panu Matilainen 8fcb96
-    spaceSize = rpmExpandNumeric("%{__gpg_reserved_space}");
Panu Matilainen 8fcb96
+    if (gpgSize > 0)
Panu Matilainen 8fcb96
+	spaceSize += gpgSize;
Panu Matilainen 8fcb96
+
Panu Matilainen 8fcb96
     if(spaceSize > 0) {
Panu Matilainen 8fcb96
 	reservedSpace = xcalloc(spaceSize, sizeof(char));
Panu Matilainen 8fcb96
 	rpmtdReset(&td);