From nobody@FreeBSD.org  Wed Jan 31 15:32:21 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 2A34916A400
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 31 Jan 2007 15:32:21 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 1B2F213C442
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 31 Jan 2007 15:32:21 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l0VFWKdF004805
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 31 Jan 2007 15:32:20 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l0VFWK3d004804;
	Wed, 31 Jan 2007 15:32:20 GMT
	(envelope-from nobody)
Message-Id: <200701311532.l0VFWK3d004804@www.freebsd.org>
Date: Wed, 31 Jan 2007 15:32:20 GMT
From: Artis Caune<Artis.Caune@latnet.lv>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] lib/libarchive core dumps on 6.2
X-Send-Pr-Version: www-3.0

>Number:         108607
>Category:       bin
>Synopsis:       [PATCH] lib/libarchive core dumps on 6.2
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    kientzle
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 31 15:40:15 GMT 2007
>Closed-Date:    Sun Feb 25 18:54:32 GMT 2007
>Last-Modified:  Sun Feb 25 18:54:32 GMT 2007
>Originator:     Artis Caune
>Release:        6.2
>Organization:
>Environment:
>Description:
After updating all boxes to 6.2, backup scripts don't work:

# tar -r -f /home/backup/pgsql.tar /home/backup/pgsql
INTERNAL ERROR: Function 'archive_read_next_header' invoked with archive structure in state 'new', should be in state 'header/data'
Segmentation fault: 11 (core dumped)

>How-To-Repeat:
# touch file.tar
# tar -r -f file.tar /COPYRIGHT

>Fix:


Patch attached with submission follows:

--- src/lib/libarchive/archive_read.c.orig	Tue Sep  5 08:23:51 2006
+++ src/lib/libarchive/archive_read.c	Wed Jan 31 17:23:46 2007
@@ -145,6 +145,7 @@
 	a->client_skipper = NULL;
 	a->client_closer = NULL;
 	a->client_data = NULL;
+	a->state = ARCHIVE_STATE_HEADER;
 
 	/* Open data source. */
 	if (client_opener != NULL) {

>Release-Note:
>Audit-Trail:

From: Remko Lodder <remko@FreeBSD.org>
To: Artis Caune <Artis.Caune@latnet.lv>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/108607: [PATCH] lib/libarchive core dumps on 6.2
Date: Wed, 31 Jan 2007 19:00:40 +0100

 Artis Caune wrote:
 After updating all boxes to 6.2, backup scripts don't work:
 > 
 > # tar -r -f /home/backup/pgsql.tar /home/backup/pgsql
 > INTERNAL ERROR: Function 'archive_read_next_header' invoked with archive structure in state 'new', should be in state 'header/data'
 > Segmentation fault: 11 (core dumped)
 > 
 >> How-To-Repeat:
 > # touch file.tar
 > # tar -r -f file.tar /COPYRIGHT
 > 
 >> Fix:
 > 
 > 
 > Patch attached with submission follows:
 > 
 > --- src/lib/libarchive/archive_read.c.orig	Tue Sep  5 08:23:51 2006
 > +++ src/lib/libarchive/archive_read.c	Wed Jan 31 17:23:46 2007
 > @@ -145,6 +145,7 @@
 >  	a->client_skipper = NULL;
 >  	a->client_closer = NULL;
 >  	a->client_data = NULL;
 > +	a->state = ARCHIVE_STATE_HEADER;
 >  
 >  	/* Open data source. */
 >  	if (client_opener != NULL) {
 > 
 As you can read with the -r option, it means append to an
 existing archive, the -c is being used to create a new archive;
 
 When i do that with
 
 # tar -cf /file.tar /etc
 
 I will get a /file.tar with the contents of /etc
 
 # tar -rf /file.tar /COPYRIGHT
 
 will add the COPYRIGHT file to the tarball.
 
 (# tar -r -f file.tar /COPYRIGHT
 tar: Removing leading '/' from member names)
 
 So, from my point of view you are using the wrong flags
 for the wrong kind of thing, i dont think setting the
 state hardcoded in the file is the idea, the state should
 be fetched from the file first.
 
 -- 
 Kind regards,
 
       Remko Lodder               ** remko@elvandar.org
       FreeBSD                    ** remko@FreeBSD.org
 
       /* Quis custodiet ipsos custodes */
Responsible-Changed-From-To: freebsd-bugs->kientzle 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Jan 31 18:01:08 UTC 2007 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=108607 

From: Tim Kientzle <tim@kientzle.com>
To: bug-followup@FreeBSD.org, Artis.Caune@latnet.lv
Cc:  
Subject: Re: bin/108607: [PATCH] lib/libarchive core dumps on 6.2
Date: Wed, 31 Jan 2007 20:26:37 -0800

 This is a multi-part message in MIME format.
 --------------030002000509030005020907
 Content-Type: text/plain; charset=us-ascii; format=flowed
 Content-Transfer-Encoding: 7bit
 
 > After updating all boxes to 6.2, backup scripts don't work:
 > 
 > # tar -r -f /home/backup/pgsql.tar /home/backup/pgsql
 > INTERNAL ERROR: Function 'archive_read_next_header' invoked with archive structure in state 'new', should be in state 'header/data'
 > Segmentation fault: 11 (core dumped)
 
 These error messages in libarchive are intended to point out
 bugs in programs that use libarchive.  In this case, bsdtar has
 tried to open an archive file with libarchive, which has
 failed because the file is not a valid archive.  bsdtar is
 not detecting this error and is making requests to libarchive
 that are nonsensical.
 
 > # touch file.tar
 > # tar -r -f file.tar /COPYRIGHT
 
 I've never been entirely comfortable with this usage, because
 "touch file.tar" does not create a legal tar archive, so
 it doesn't really make sense to me to "add a file to
 an archive" when the archive is invalid.  (This is why
 archive_read_open() fails above; an empty file is not
 a legal tar archive.)
 
 In particular, bsdtar can actually append to several different
 archive formats; for -r it first tries to determine the format
 of the archive it is appending to, which always fails if the
 archive file is empty or non-existent.
 
 But I do get a lot of complaints about this, so I put together the
 attached patch for usr.bin/tar/write.c.  This changes bsdtar's
 handling for -r so that it will silently try -c if the
 file is empty or non-existent.  Let me know if it works
 for you.
 
 Tim Kientzle
 
 
 --------------030002000509030005020907
 Content-Type: text/x-patch;
  name="tar-r-on-empty-or-nonexistent-file.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="tar-r-on-empty-or-nonexistent-file.patch"
 
 Index: write.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/tar/write.c,v
 retrieving revision 1.51
 diff -u -r1.51 write.c
 --- write.c	9 Jan 2007 08:12:17 -0000	1.51
 +++ write.c	1 Feb 2007 04:17:03 -0000
 @@ -213,6 +213,8 @@
  	int	format;
  	struct archive *a;
  	struct archive_entry *entry;
 +	int	r;
 +	struct stat st;
  
  	/* Sanity-test some arguments and the file. */
  	test_for_append(bsdtar);
 @@ -220,15 +222,29 @@
  	format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
  
  	bsdtar->fd = open(bsdtar->filename, O_RDWR);
 -	if (bsdtar->fd < 0)
 +	if (bsdtar->fd < 0) {
 +		if (errno == ENOENT)
 +			return (tar_mode_c(bsdtar));
  		bsdtar_errc(bsdtar, 1, errno,
  		    "Cannot open %s", bsdtar->filename);
 +	}
  
  	a = archive_read_new();
  	archive_read_support_compression_all(a);
  	archive_read_support_format_tar(a);
  	archive_read_support_format_gnutar(a);
 -	archive_read_open_fd(a, bsdtar->fd, 10240);
 +	r = archive_read_open_fd(a, bsdtar->fd, 10240);
 +	if (r != ARCHIVE_OK) {
 +		if (fstat(bsdtar->fd, &st) != 0) {
 +			bsdtar_errc(bsdtar, 1, errno,
 +			    "Cannot stat %s", bsdtar->filename);
 +		}
 +		if (st.st_size == 0)
 +			return (tar_mode_c(bsdtar));
 +		bsdtar_errc(bsdtar, 1, archive_errno(a),
 +		    "Can't read archive %s: %s", bsdtar->filename,
 +		    archive_error_string(a));
 +	}
  	while (0 == archive_read_next_header(a, &entry)) {
  		if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) {
  			archive_read_finish(a);
 @@ -1433,8 +1449,7 @@
  		    "Cannot append to %s with compression", bsdtar->filename);
  
  	if (stat(bsdtar->filename, &s) != 0)
 -		bsdtar_errc(bsdtar, 1, errno,
 -		    "Cannot stat %s", bsdtar->filename);
 +		return;
  
  	if (!S_ISREG(s.st_mode))
  		bsdtar_errc(bsdtar, 1, 0,
 
 --------------030002000509030005020907--

From: Artis Caune <Artis.Caune@latnet.lv>
To: remko@FreeBSD.org
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/108607: [PATCH] lib/libarchive core dumps on 6.2
Date: Thu, 01 Feb 2007 09:52:38 +0200

 Remko Lodder wrote:
 > Artis Caune wrote:
 > After updating all boxes to 6.2, backup scripts don't work:
 >>
 >> # tar -r -f /home/backup/pgsql.tar /home/backup/pgsql
 >> INTERNAL ERROR: Function 'archive_read_next_header' invoked with 
 >> archive structure in state 'new', should be in state 'header/data'
 >> Segmentation fault: 11 (core dumped)
 >>
 >>> How-To-Repeat:
 >> # touch file.tar
 >> # tar -r -f file.tar /COPYRIGHT
 >>
 >>> Fix:
 >>
 >>
 >> Patch attached with submission follows:
 >>
 >> --- src/lib/libarchive/archive_read.c.orig    Tue Sep  5 08:23:51 2006
 >> +++ src/lib/libarchive/archive_read.c    Wed Jan 31 17:23:46 2007
 >> @@ -145,6 +145,7 @@
 >>      a->client_skipper = NULL;
 >>      a->client_closer = NULL;
 >>      a->client_data = NULL;
 >> +    a->state = ARCHIVE_STATE_HEADER;
 >>  
 >>      /* Open data source. */
 >>      if (client_opener != NULL) {
 >>
 > As you can read with the -r option, it means append to an
 > existing archive, the -c is being used to create a new archive;
 > 
 > When i do that with
 > 
 > # tar -cf /file.tar /etc
 > 
 > I will get a /file.tar with the contents of /etc
 > 
 > # tar -rf /file.tar /COPYRIGHT
 > 
 > will add the COPYRIGHT file to the tarball.
 > 
 > (# tar -r -f file.tar /COPYRIGHT
 > tar: Removing leading '/' from member names)
 > 
 > So, from my point of view you are using the wrong flags
 > for the wrong kind of thing, i dont think setting the
 > state hardcoded in the file is the idea, the state should
 > be fetched from the file first.
 > 
 
 
 It works in 6.1 and in 4.x (gnutar)
 
 bsdtar man page say:
    "Like -c, but new entries are appended to the archive."
 and mode_c create archive if file does not exist.
 
 I though if I can append text to file, even nonexistant,
     # echo "text" >> /no_such_file
 than I can append to archive too.
 
 But if this is wrong, I can always use other ways to add files to archive:
 
 # if [ -f file.tar ]; then \
      tar -r -f file.tar /all_other_files \
    else \
      tar -c -f file.tar /etc/passwd \
    fi
 
 or
 
 # tar -c -f file.tar -T /list_of_files
 

From: Artis Caune <Artis.Caune@latnet.lv>
To: Tim Kientzle <tim@kientzle.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/108607: [PATCH] lib/libarchive core dumps on 6.2
Date: Thu, 01 Feb 2007 10:22:39 +0200

 Tim Kientzle wrote:
 >> After updating all boxes to 6.2, backup scripts don't work:
 >>
 >> # tar -r -f /home/backup/pgsql.tar /home/backup/pgsql
 >> INTERNAL ERROR: Function 'archive_read_next_header' invoked with 
 >> archive structure in state 'new', should be in state 'header/data'
 >> Segmentation fault: 11 (core dumped)
 > 
 > These error messages in libarchive are intended to point out
 > bugs in programs that use libarchive.  In this case, bsdtar has
 > tried to open an archive file with libarchive, which has
 > failed because the file is not a valid archive.  bsdtar is
 > not detecting this error and is making requests to libarchive
 > that are nonsensical.
 > 
 >> # touch file.tar
 >> # tar -r -f file.tar /COPYRIGHT
 > 
 > I've never been entirely comfortable with this usage, because
 > "touch file.tar" does not create a legal tar archive, so
 > it doesn't really make sense to me to "add a file to
 > an archive" when the archive is invalid.  (This is why
 > archive_read_open() fails above; an empty file is not
 > a legal tar archive.)
 > 
 > In particular, bsdtar can actually append to several different
 > archive formats; for -r it first tries to determine the format
 > of the archive it is appending to, which always fails if the
 > archive file is empty or non-existent.
 
 btw, how about this:
 # echo "this is text file" > /no_such_file.tar
 # tar -r -f /no_such_file.tar /COPYRIGHT
 :)
 
 
 > But I do get a lot of complaints about this, so I put together the
 > attached patch for usr.bin/tar/write.c.  This changes bsdtar's
 > handling for -r so that it will silently try -c if the
 > file is empty or non-existent.  Let me know if it works
 > for you.
 > 
 > Tim Kientzle
 
 
 Thanks, patch works fine.
 
 
 Maybe just use code from mode_u and return error?
 
 -       archive_read_open_fd(a, bsdtar->fd, 10240);
 +       if (archive_read_open_fd(a, bsdtar->fd,
 +           bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
 +               DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
 +               bsdtar_errc(bsdtar, 1, 0,
 +                   "Can't open %s: %s", bsdtar->filename,
 +                   archive_error_string(a));
 +       }
 

From: Tim Kientzle <tim@kientzle.com>
To: Artis Caune <Artis.Caune@latnet.lv>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/108607: [PATCH] lib/libarchive core dumps on 6.2
Date: Thu, 01 Feb 2007 23:16:31 -0800

 >> ... the attached patch for usr.bin/tar/write.c ... changes bsdtar's
 >> handling for -r so that it will silently try -c if the
 >> file is empty or non-existent.
 > 
 > Thanks, patch works fine.
 
 I think I've found a much cleaner approach that I'm implementing
 in -CURRENT now.  It extends libarchive to support empty
 files as a special case, and then requires some minor mods
 to bsdtar.
 
 Part of this is committed to -CURRENT; the rest will follow
 shortly.
 
 Tim Kientzle

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/108607: commit references a PR
Date: Wed, 14 Feb 2007 08:29:42 +0000 (UTC)

 kientzle    2007-02-14 08:29:35 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     lib/libarchive       Makefile archive.h.in archive_read.3 
                          archive_read.c 
                          archive_read_support_format_all.c 
   Added files:           (Branch: RELENG_6)
     lib/libarchive       archive_read_support_format_empty.c 
   Log:
   MFC: "empty" format support
   PR: bin/108607
   
   Revision  Changes    Path
   1.36.2.4  +1 -0      src/lib/libarchive/Makefile
   1.23.2.5  +2 -0      src/lib/libarchive/archive.h.in
   1.20.2.4  +15 -1     src/lib/libarchive/archive_read.3
   1.15.2.6  +0 -10     src/lib/libarchive/archive_read.c
   1.6.2.2   +1 -0      src/lib/libarchive/archive_read_support_format_all.c
   1.1.2.1   +90 -0     src/lib/libarchive/archive_read_support_format_empty.c (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/108607: commit references a PR
Date: Sun, 25 Feb 2007 07:24:51 +0000 (UTC)

 kientzle    2007-02-25 07:24:45 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.bin/tar          write.c 
   Log:
   MFC write.c 1.54.  This implements -r support for empty or
   nonexistent files and corrects the bad handling of files that
   change size during archiving.
   
   PR: bin/108607
   PR: bin/108990
   
   Revision  Changes    Path
   1.41.2.5  +47 -13    src/usr.bin/tar/write.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: kientzle 
State-Changed-When: Sun Feb 25 18:53:59 UTC 2007 
State-Changed-Why:  
Fixed in -CURRENT and 6-STABLE. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=108607 
>Unformatted:
