gpgtar: Fix extracting files with !(size % 512)
authorAndre Heinecke <aheinecke@intevation.de>
Tue, 17 Mar 2015 09:48:09 +0000 (10:48 +0100)
committerWerner Koch <wk@gnupg.org>
Tue, 17 Mar 2015 10:55:22 +0000 (11:55 +0100)
* tools/gpgtar-extract.c (extract_regular): Handle size multiples
  of RECORDSIZE.

--
  If a hdr->size was a multiple of 512 the last record would
  not have been written and the files corrupted accordingly.

GnuPG-bug-id: 1926

Signed-off-by: Andre Heinecke <aheinecke@intevation.de>
Changed to use only if-else.

Signed-off-by: Werner Koch <wk@gnupg.org>
tools/gpgtar-extract.c

index 1ea3597..6e506d9 100644 (file)
@@ -66,7 +66,11 @@ extract_regular (estream_t stream, const char *dirname,
       if (err)
         goto leave;
       n++;
-      nbytes = (n < hdr->nrecords)? RECORDSIZE : (hdr->size % RECORDSIZE);
+      if (n < hdr->nrecords || (hdr->size && !(hdr->size % RECORDSIZE)))
+        nbytes = RECORDSIZE;
+      else
+        nbytes = (hdr->size % RECORDSIZE);
+
       nwritten = es_fwrite (record, 1, nbytes, outfp);
       if (nwritten != nbytes)
         {