Blame SOURCES/tar-1.30-padding-zeros.patch

edaf32
From 910d9ff829bbdfaf1455cdb2b1813507bcb855ec Mon Sep 17 00:00:00 2001
edaf32
From: Ondrej Dubaj <odubaj@redhat.com>
edaf32
Date: Tue, 13 Apr 2021 11:47:32 +0200
edaf32
Subject: [PATCH] add padding message, when read error occurs and tar is
edaf32
 padding with zeros
edaf32
edaf32
---
edaf32
 lib/paxerror.c | 44 ++++++++++++++++++++++++++++++--------------
edaf32
 lib/paxlib.h   |  4 ++--
edaf32
 src/common.h   |  2 +-
edaf32
 src/create.c   |  2 +-
edaf32
 src/misc.c     |  6 +++---
edaf32
 src/sparse.c   |  6 +++---
edaf32
 6 files changed, 40 insertions(+), 24 deletions(-)
edaf32
edaf32
diff --git a/lib/paxerror.c b/lib/paxerror.c
edaf32
index 134cef3..929a741 100644
edaf32
--- a/lib/paxerror.c
edaf32
+++ b/lib/paxerror.c
edaf32
@@ -173,29 +173,45 @@ read_error (char const *name)
edaf32
 }
edaf32
 
edaf32
 void
edaf32
-read_error_details (char const *name, off_t offset, size_t size)
edaf32
+read_error_details (char const *name, off_t offset, size_t size, bool padding)
edaf32
 {
edaf32
   char buf[UINTMAX_STRSIZE_BOUND];
edaf32
   int e = errno;
edaf32
-  ERROR ((0, e,
edaf32
-	  ngettext ("%s: Read error at byte %s, while reading %lu byte",
edaf32
-		    "%s: Read error at byte %s, while reading %lu bytes",
edaf32
-		    size),
edaf32
-	  quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
edaf32
-	  (unsigned long) size));
edaf32
+  if (padding)
edaf32
+    ERROR ((0, e,
edaf32
+      ngettext ("%s: Read error at byte %s, while reading %lu byte; padding with zeros",
edaf32
+          "%s: Read error at byte %s, while reading %lu bytes; padding with zeros",
edaf32
+          size),
edaf32
+      quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
edaf32
+      (unsigned long) size));
edaf32
+  else
edaf32
+    ERROR ((0, e,
edaf32
+      ngettext ("%s: Read error at byte %s, while reading %lu byte",
edaf32
+          "%s: Read error at byte %s, while reading %lu bytes",
edaf32
+          size),
edaf32
+      quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
edaf32
+      (unsigned long) size));
edaf32
 }
edaf32
 
edaf32
 void
edaf32
-read_warn_details (char const *name, off_t offset, size_t size)
edaf32
+read_warn_details (char const *name, off_t offset, size_t size, bool padding)
edaf32
 {
edaf32
   char buf[UINTMAX_STRSIZE_BOUND];
edaf32
   int e = errno;
edaf32
-  WARN ((0, e,
edaf32
-	 ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte",
edaf32
-		   "%s: Warning: Read error at byte %s, while reading %lu bytes",
edaf32
-		   size),
edaf32
-	 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
edaf32
-	 (unsigned long) size));
edaf32
+  if (padding)
edaf32
+    WARN ((0, e,
edaf32
+      ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte; padding with zeros",
edaf32
+          "%s: Warning: Read error at byte %s, while reading %lu bytes; padding with zeros",
edaf32
+          size),
edaf32
+      quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
edaf32
+      (unsigned long) size));
edaf32
+  else
edaf32
+    WARN ((0, e,
edaf32
+      ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte",
edaf32
+          "%s: Warning: Read error at byte %s, while reading %lu bytes",
edaf32
+          size),
edaf32
+      quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
edaf32
+      (unsigned long) size));
edaf32
 }
edaf32
 
edaf32
 void
edaf32
diff --git a/lib/paxlib.h b/lib/paxlib.h
edaf32
index d4251d1..ccf826b 100644
edaf32
--- a/lib/paxlib.h
edaf32
+++ b/lib/paxlib.h
edaf32
@@ -94,10 +94,10 @@ void open_error (char const *);
edaf32
 void open_fatal (char const *) __attribute__ ((noreturn));
edaf32
 void open_warn (char const *);
edaf32
 void read_error (char const *);
edaf32
-void read_error_details (char const *, off_t, size_t);
edaf32
+void read_error_details (char const *, off_t, size_t, bool);
edaf32
 void read_fatal (char const *) __attribute__ ((noreturn));
edaf32
 void read_fatal_details (char const *, off_t, size_t) __attribute__ ((noreturn));
edaf32
-void read_warn_details (char const *, off_t, size_t);
edaf32
+void read_warn_details (char const *, off_t, size_t, bool);
edaf32
 void readlink_error (char const *);
edaf32
 void readlink_warn (char const *);
edaf32
 void rmdir_error (char const *);
edaf32
diff --git a/src/common.h b/src/common.h
edaf32
index bbe167e..34a30ec 100644
edaf32
--- a/src/common.h
edaf32
+++ b/src/common.h
edaf32
@@ -713,7 +713,7 @@ int chdir_count (void);
edaf32
 
edaf32
 void close_diag (char const *name);
edaf32
 void open_diag (char const *name);
edaf32
-void read_diag_details (char const *name, off_t offset, size_t size);
edaf32
+void read_diag_details (char const *name, off_t offset, size_t size, bool padding);
edaf32
 void readlink_diag (char const *name);
edaf32
 void savedir_diag (char const *name);
edaf32
 void seek_diag_details (char const *name, off_t offset);
edaf32
diff --git a/src/create.c b/src/create.c
edaf32
index 712ee18..181f7d9 100644
edaf32
--- a/src/create.c
edaf32
+++ b/src/create.c
edaf32
@@ -1090,7 +1090,7 @@ dump_regular_file (int fd, struct tar_stat_info *st)
edaf32
       if (count == SAFE_READ_ERROR)
edaf32
 	{
edaf32
 	  read_diag_details (st->orig_file_name,
edaf32
-	                     st->stat.st_size - size_left, bufsize);
edaf32
+	                     st->stat.st_size - size_left, bufsize, true);
edaf32
 	  pad_archive (size_left);
edaf32
 	  return dump_status_short;
edaf32
 	}
edaf32
diff --git a/src/misc.c b/src/misc.c
edaf32
index eccf6f9..28c6f44 100644
edaf32
--- a/src/misc.c
edaf32
+++ b/src/misc.c
edaf32
@@ -1069,15 +1069,15 @@ open_diag (char const *name)
edaf32
 }
edaf32
 
edaf32
 void
edaf32
-read_diag_details (char const *name, off_t offset, size_t size)
edaf32
+read_diag_details (char const *name, off_t offset, size_t size, bool padding)
edaf32
 {
edaf32
   if (ignore_failed_read_option)
edaf32
     {
edaf32
       if (WARNING_ENABLED(WARN_FAILED_READ))
edaf32
-	read_warn_details (name, offset, size);
edaf32
+	read_warn_details (name, offset, size, padding);
edaf32
     }
edaf32
   else
edaf32
-    read_error_details (name, offset, size);
edaf32
+    read_error_details (name, offset, size, padding);
edaf32
 }
edaf32
 
edaf32
 void
edaf32
diff --git a/src/sparse.c b/src/sparse.c
edaf32
index 55c874f..1f9f0af 100644
edaf32
--- a/src/sparse.c
edaf32
+++ b/src/sparse.c
edaf32
@@ -425,7 +425,7 @@ sparse_dump_region (struct tar_sparse_file *file, size_t i)
edaf32
 	                     (file->stat_info->sparse_map[i].offset
edaf32
 			      + file->stat_info->sparse_map[i].numbytes
edaf32
 			      - bytes_left),
edaf32
-			     bufsize);
edaf32
+			     bufsize, false);
edaf32
 	  return false;
edaf32
 	}
edaf32
       if (bytes_read == 0)
edaf32
@@ -607,7 +607,7 @@ check_sparse_region (struct tar_sparse_file *file, off_t beg, off_t end)
edaf32
       if (bytes_read == SAFE_READ_ERROR)
edaf32
 	{
edaf32
           read_diag_details (file->stat_info->orig_file_name,
edaf32
-	                     offset, rdsize);
edaf32
+	                     offset, rdsize, false);
edaf32
 	  return false;
edaf32
 	}
edaf32
 
edaf32
@@ -657,7 +657,7 @@ check_data_region (struct tar_sparse_file *file, size_t i)
edaf32
 			     (file->stat_info->sparse_map[i].offset
edaf32
 			      + file->stat_info->sparse_map[i].numbytes
edaf32
 			      - size_left),
edaf32
-			     rdsize);
edaf32
+			     rdsize, false);
edaf32
 	  return false;
edaf32
 	}
edaf32
       file->dumped_size += bytes_read;
edaf32
-- 
edaf32
2.30.2
edaf32