NetBSD Problem Report #35048

From www@NetBSD.org  Mon Nov 13 21:25:43 2006
Return-Path: <www@NetBSD.org>
Received: by narn.NetBSD.org (Postfix, from userid 31301)
	id 3211E63B400; Mon, 13 Nov 2006 21:25:43 +0000 (UTC)
Message-Id: <20061113212543.3211E63B400@narn.NetBSD.org>
Date: Mon, 13 Nov 2006 21:25:43 +0000 (UTC)
From: b1ff@fr33.b33r.net
Reply-To: b1ff@fr33.b33r.net
To: gnats-bugs@NetBSD.org
Subject: when compressing, gzip(1) unlinks input even if output can't be written
X-Send-Pr-Version: www-1.0

>Number:         35048
>Category:       bin
>Synopsis:       when compressing, gzip(1) unlinks input even if output can't be written
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mrg
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 13 21:30:00 +0000 2006
>Closed-Date:    Fri Nov 14 08:23:45 +0000 2008
>Last-Modified:  Fri Nov 14 08:23:45 +0000 2008
>Originator:     Mathieu
>Release:        3.0.1
>Organization:
>Environment:
>Description:
If writing fails (like when the FS gets full), gzip will still delete the input file. Ouch.

>How-To-Repeat:
$ df -h .
Filesystem    Size      Used     Avail Capacity  Mounted on
/dev/vnd1a     19M     1.0K       18M     0%    /mnt
$ dd if=/dev/zero of=test bs=1m count=10
10+0 records in
10+0 records out
10485760 bytes transferred in 0.225 secs (46603377 bytes/sec)
$ cp /netbsd .                              
$ gzip netbsd                               

/mnt: write failed, file system is full
gzip: write: No space left on device
$ ls -l
total 10448
-rwx------  1 mathieu  wheel    196608 Nov 13 15:46 netbsd.gz
-rw-------  1 mathieu  wheel  10485760 Nov 13 15:46 test
$ gzip -t netbsd.gz 
gzip: netbsd.gz: unexpected end of file

>Fix:
/*      $NetBSD: gzip.c,v 1.71.2.5 2005/11/27 23:09:46 riz Exp $        */

--- gzip.c	2006-11-13 16:12:57.000000000 -0500
+++ gzip.c.orig	2006-11-13 16:13:45.000000000 -0500
@@ -561,7 +561,7 @@
 		if (z.avail_out == 0) {
 			if (write(out, outbufp, BUFLEN) != BUFLEN) {
 				maybe_warn("write");
-				in_tot = -1;
+				out_tot = -1;
 				goto out;
 			}


It seems like there's a simple typo there. I'm not sure if it fixes completely the problem yet... but it does seem to work here.

$ gzip netbsd
gzip: output file: netbsd.gz wrong size (2293760 != -1), deleting
gzip: leaving original netbsd
$ ls -l
total 16528
-rwx------  1 mathieu  wheel  8514752 Nov 13 16:12 netbsd
-rw-------  1 mathieu  wheel  8388608 Nov 13 15:58 test

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: bin-bug-people->mrg
Responsible-Changed-By: mrg@netbsd.org
Responsible-Changed-When: Mon, 13 Nov 2006 21:59:43 +0000
Responsible-Changed-Why:
this is mine.  i will request pullup to netbsd-3 branches in a
couple of days.


From: matthew green <mrg@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: PR/35048 CVS commit: src/usr.bin/gzip
Date: Mon, 13 Nov 2006 21:57:59 +0000 (UTC)

 Module Name:	src
 Committed By:	mrg
 Date:		Mon Nov 13 21:57:59 UTC 2006

 Modified Files:
 	src/usr.bin/gzip: gzip.c

 Log Message:
 properly detect when the output fails (eg, full filesystem) and do not
 delete the input file.  patch from PR#35048.


 To generate a diff of this commit:
 cvs rdiff -r1.88 -r1.89 src/usr.bin/gzip/gzip.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->pending-pullups
State-Changed-By: mrg@NetBSD.org
State-Changed-When: Fri, 07 Nov 2008 05:24:56 +0000
State-Changed-Why:
pullups to netbsd-3 have been submitted, this is fixed in netbsd-4 since
that was branch.


From: Soren Jacobsen <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/35048 CVS commit: [netbsd-3] src/usr.bin/gzip
Date: Fri, 14 Nov 2008 03:08:32 +0000 (UTC)

 Module Name:	src
 Committed By:	snj
 Date:		Fri Nov 14 03:08:32 UTC 2008

 Modified Files:
 	src/usr.bin/gzip [netbsd-3]: gzip.c

 Log Message:
 Pull up following revision(s) (requested by mrg in ticket #1978):
 	usr.bin/gzip/gzip.c: revision 1.89
 properly detect when the output fails (eg, full filesystem) and do not
 delete the input file.  patch from PR#35048.


 To generate a diff of this commit:
 cvs rdiff -r1.71.2.6 -r1.71.2.7 src/usr.bin/gzip/gzip.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: mrg@NetBSD.org
State-Changed-When: Fri, 14 Nov 2008 08:23:45 +0000
State-Changed-Why:
all done, thanks.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.