Re: tar dumps core when appending to empty file

From: Ryan Sommers <ryans_at_gamersimpact.com>
Date: Sun, 24 Oct 2004 09:45:00 -0500
Jason C. Wells wrote:

> What I am trying to do is:
>
> $ touch Makefiles.tar
> $ find . -name Makefile.orig -exec tar -r -f Makefiles.tar {} \;
>
> This causes tar to dump core as fast as find can find the specified 
> files.
>
> So I tried:
>
> $ touch Makefiles.tar
> $ tar -r -f Makefiles.tar Makefile.inc1
>
> And also got a core dump.  I then tried:
>
> $ tar -c -f Makefiles.tar Makefile.inc1
> $ find . -name Makefile.orig -exec tar -r -f Makefiles.tar {} \;
>
> This worked as I expected.
>
> I seem to have uncovered a bug.  It seems reasonable to me to append 
> to an empty file.  Perhaps I am missing some sort of arcana here.
>
> Later,
> Jason C. Wells

The following patch appears to fix this:

Index: archive_read_support_format_tar.c
===================================================================
RCS file: /home/ncvs/src/lib/libarchive/archive_read_support_format_tar.c,v
retrieving revision 1.27
diff -u -r1.27 archive_read_support_format_tar.c
--- archive_read_support_format_tar.c    4 Sep 2004 21:49:42 -0000    1.27
+++ archive_read_support_format_tar.c    24 Oct 2004 14:42:04 -0000
_at__at_ -270,7 +270,10 _at__at_
         bid++;
 
     /* Now let's look at the actual header and see if it matches. */
-    bytes_read = (a->compression_read_ahead)(a, &h, 512);
+    if (a->compression_read_ahead)
+        bytes_read = (a->compression_read_ahead)(a, &h, 512);
+    else
+        bytes_read = 0;
     if (bytes_read < 0)
         return (ARCHIVE_FATAL);
     if (bytes_read == 0  &&  bid > 0) {

Tim, reply to me if you want me to PR'ify this for ya.

-- 
Ryan Sommers
ryans_at_gamersimpact.com


Index: archive_read_support_format_tar.c
===================================================================
RCS file: /home/ncvs/src/lib/libarchive/archive_read_support_format_tar.c,v
retrieving revision 1.27
diff -u -r1.27 archive_read_support_format_tar.c
--- archive_read_support_format_tar.c	4 Sep 2004 21:49:42 -0000	1.27
+++ archive_read_support_format_tar.c	24 Oct 2004 14:42:04 -0000
_at__at_ -270,7 +270,10 _at__at_
 		bid++;
 
 	/* Now let's look at the actual header and see if it matches. */
-	bytes_read = (a->compression_read_ahead)(a, &h, 512);
+	if (a->compression_read_ahead)
+		bytes_read = (a->compression_read_ahead)(a, &h, 512);
+	else
+		bytes_read = 0;
 	if (bytes_read < 0)
 		return (ARCHIVE_FATAL);
 	if (bytes_read == 0  &&  bid > 0) {
Received on Sun Oct 24 2004 - 12:44:56 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:19 UTC