From jkoshy@FreeBSD.ORG  Wed Sep 30 02:56:19 1998
Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA04499
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Sep 1998 02:56:19 -0700 (PDT)
          (envelope-from jkoshy@FreeBSD.org)
Received: (from jkoshy@localhost)
	by freefall.freebsd.org (8.8.8/8.8.5) id CAA18215;
	Wed, 30 Sep 1998 02:56:14 -0700 (PDT)
Message-Id: <199809300956.CAA18215@freefall.freebsd.org>
Date: Wed, 30 Sep 1998 02:56:14 -0700 (PDT)
From: Erik E Rantapaa <rantapaa@uswest.net>
Reply-To: Erik E Rantapaa <rantapaa@uswest.net>
To: FreeBSD-gnats-submit@FreeBSD.org
Subject: some bugs in cpio
X-Send-Pr-Version: 3.2

>Number:         8099
>Category:       gnu
>Synopsis:       [patch] some bugs in cpio
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    obrien
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 30 03:00:01 PDT 1998
>Closed-Date:    Sun Nov 13 07:35:01 GMT 2005
>Last-Modified:  Sun Nov 13 07:35:01 GMT 2005
>Originator:     Erik E Rantapaa
>Release:        FreeBSD 2.2.6-STABLE i386
>Organization:
US West
>Environment:

	

>Description:

[[ 
Submitted by jkoshy on behalf of Erik E Rantapaa <rantapaa@uswest.net>
Message-id: <Pine.BSF.3.91.980929194106.14261A-200000@tahiti.oss.uswest.net>
sent to freebsd-ports@freebsd.org
]] 

Hello Freebsd-ers...

I fixed a few bugs in cpio-2.4.2 and have just sent a bug report to the GNU
folks.  I also thought I would report them here since FreeBSD uses GNU cpio
as part of its base system.

If there is a better way to report these kind of things, please let me know
and I'll note it for future reference.

Cheers,

Erik Rantapaa
rantapaa@uswest.net

---------- Forwarded message ----------
Date: Tue, 29 Sep 1998 19:15:49 -0500 (CDT)
From: Erik E Rantapaa <rantapaa@tahiti.oss.uswest.net>
To: bug-gnu-utils@prep.ai.mit.edu
Subject: some bugs in cpio

Hello,

Here are some bugs I found in cpio-2.4.2.  I have tested the fix for
bug #1 and it seems to work. I have not run into bug #2 yet, so the
fix I have for that is more speculative, although I'm pretty sure it is
the right thing to do.

A patch file is included.

--
Erik Rantapaa
rantapaa@uswest.net


Bug #1: cpio writes corrupted archives when archiving growing files

Description:

If a file that cpio is archiving grows in size during the archiving process, 
the growth will appear as part of the next file placed into the archive.
This results in a corrupted archive.

The problem is that that cpio is not resetting its input buffer when
it opens a new file.

Fix:

Reset the input buffer by setting input_size = 0 in a few places
-- specifically whenever a new file is designated to be the one
that uses the input buffer.

Bug #2: cpio may not handle file shrinkage properly

Description:

>How-To-Repeat:

	

>Fix:

diff -u cpio-2.4.2/copyout.c cpio-2.4.2-fixed/copyout.c
--- cpio-2.4.2/copyout.c	Wed Jan 10 10:10:45 1996
+++ cpio-2.4.2-fixed/copyout.c	Tue Sep 29 18:35:50 1998
@@ -369,6 +369,7 @@
 		    }
 		}
 #endif
+	      input_size = 0;
 	      in_file_des = open (input_name.ds_string,
 				  O_RDONLY | O_BINARY, 0);
 	      if (in_file_des < 0)
@@ -770,6 +771,7 @@
   file_hdr = *header;
 
 
+  input_size = 0;
   in_file_des = open (header->c_name,
 		      O_RDONLY | O_BINARY, 0);
   if (in_file_des < 0)
Only in cpio-2.4.2-fixed: copyout.o
diff -u cpio-2.4.2/copypass.c cpio-2.4.2-fixed/copypass.c
--- cpio-2.4.2/copypass.c	Mon Jan  8 15:59:05 1996
+++ cpio-2.4.2-fixed/copypass.c	Tue Sep 29 18:38:48 1998
@@ -147,6 +147,7 @@
 	  /* If the file was not linked, copy contents of file.  */
 	  if (link_res < 0)
 	    {
+	      input_size = 0;
 	      in_file_des = open (input_name.ds_string,
 				  O_RDONLY | O_BINARY, 0);
 	      if (in_file_des < 0)
diff -u cpio-2.4.2/util.c cpio-2.4.2-fixed/util.c
--- cpio-2.4.2/util.c	Tue Jan 16 15:40:14 1996
+++ cpio-2.4.2-fixed/util.c	Tue Sep 29 19:01:02 1998
@@ -497,6 +497,7 @@
 	    else
 	      error (0, 0, "Read error at byte %ld in file %s, padding with zeros",
 			original_num_bytes - num_bytes, filename);
+	    tape_empty_output_buffer(out_des);
 	    write_nuls_to_file (num_bytes, out_des);
 	    break;
 	  }
@@ -544,6 +545,7 @@
 	    else
 	      error (0, 0, "Read error at byte %ld in file %s, padding with zeros",
 			original_num_bytes - num_bytes, filename);
+	    disk_empty_output_buffer(out_des);
 	    write_nuls_to_file (num_bytes, out_des);
 	    break;
 	  }

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: johan 
Responsible-Changed-When: Mon Aug 14 06:47:23 PDT 2000 
Responsible-Changed-Why:  
David, you did the import of cpio into contib. 
Can youplease have a look a this and decide what to do with  
this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=8099 
State-Changed-From-To: open->patched 
State-Changed-By: tjr 
State-Changed-When: Sat Oct 1 10:34:38 GMT 2005 
State-Changed-Why:  
I believe this bug is fixed in GNU cpio 2.6 on -current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=8099 
State-Changed-From-To: patched->feedback 
State-Changed-By: linimon 
State-Changed-When: Sun Nov 13 07:27:21 GMT 2005 
State-Changed-Why:  
Has this problem been fixed with the import into -CURRENT? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=8099 
State-Changed-From-To: feedback->closed 
State-Changed-By: linimon 
State-Changed-When: Sun Nov 13 07:34:47 GMT 2005 
State-Changed-Why:  
Submitter's email address bounces. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=8099 
>Unformatted:
 >From the code it appears that cpio may not handle files which shrink
 during the archiving process in the most desirable way.  The code
 attempts to pad the missing content with nulls.  However, those nulls
 are written to the file descriptor directly with write(), whereas normally 
 file data is written through a buffer.  This could result in the nulls
 being placed somewhere in the middle of the file instead of at the end
 where it would make more sense for them to be.
 
 Fix:
 
 Call disk_empty_output_buffer() / tape_empty_output_buffer() (whichever
 is appropriate) before calling write_nuls_to_file().
 
