From owner-freebsd-bugs Wed Sep 30 03:00:19 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id DAA04885 for freebsd-bugs-outgoing; Wed, 30 Sep 1998 03:00:19 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) 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 DAA04858 for ; Wed, 30 Sep 1998 03:00:09 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id DAA18454; Wed, 30 Sep 1998 03:00:01 -0700 (PDT) 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 ; 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 Reply-To: Erik E Rantapaa To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: gnu/8099: some bugs in cpio Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 8099 >Category: gnu >Synopsis: some bugs in cpio >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Sep 30 03:00:01 PDT 1998 >Last-Modified: >Originator: Erik E Rantapaa >Organization: US West >Release: FreeBSD 2.2.6-STABLE i386 >Environment: >Description: [[ Submitted by jkoshy on behalf of Erik E Rantapaa Message-id: 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 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; } >Audit-Trail: >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(). To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message