compress bug: 'zcat x.Z' removes file 'x' if interrupted

Rick Perry perry at vu-vlsi.Villanova.EDU
Wed Apr 13 22:23:04 AEST 1988


   The problem is that, while using 'zcat x.Z', if you ^C interrupt, it
removes the file 'x'.  Normally you wouldn't have files 'x' and 'x.Z'
present at the same time, but there are times when you might, for example,
the case that caught me: I was using 'uncompressdir &' on a big dir and not
wanting to wait for all the files to be uncompressed, I did 'zcat Makefile.Z'
then aborted the zcat after I saw what I wanted and poof! neither Makefile
nor Makefile.Z existed anymore.  The uncompressdir must have been in the
process of uncompressing Makefile.Z while I was zcat'ing it, then uncompress
removed Makefile.Z when it was done and the aborted zcat removed Makefile.

   I am using version 1.14 of compress.c as distributed with the news sources
B 2.11 patchlevel 12, on a Pyramid 90x OSx4.1 machine in ucb universe.  Here's
a script demonstrating the problem:

# ls
LOGFILE		LOGFILE.Z
# /usr/old/zcat LOGFILE.Z
Tue Jan 26 13:06:51 1988	kussay (284)	2
Tue Jan 26 13:09:49 1988	perry (103)	1
^C
# ls
LOGFILE.Z
#

  Following are the compress source diffs showing how I changed onintr()
so that it performs unlink(ofname) only if zcat_flg == 0 (zcat_flg is 1
if output is going to stdout).  And just to be sure an undesirable unlink
doesn't occur for other reasons, I also added the zcat_flg check to
writeerr() and oops().  There are unlink's in copystat(), but that's only
called if zcat_flg==0 in the first place, so I didn't modify that.

...Rick			perry at vu-vlsi.UUCP, perry at vuvaxcom.BITNET

Dr. Rick Perry, Department of Electrical Engineering
Villanova University, Villanova, PA 19085, 215-645-4969, -4970

*** compress.c.1.14	Mon Apr 11 21:16:09 1988
--- compress.c	Tue Apr 12 17:12:47 1988
***************
*** 1,5
  #ifdef SCCSID
! static char	*SccsId = "@(#)compress.c	1.14	9/24/87";
  #endif /* SCCSID */
  static char rcs_ident[] = "Based on compress.c,v 4.0 85/07/30 12:50:00 joe Release";
  

--- 1,5 -----
  #ifdef SCCSID
! static char	*SccsId = "@(#)compress.c	1.15	4/12/88";
  #endif /* SCCSID */
  static char rcs_ident[] = "Based on compress.c,v 4.0 85/07/30 12:50:00 joe Release";
  
***************
*** 1185,1191
  writeerr()
  {
      perror ( ofname );
!     unlink ( ofname );
      exit ( 1 );
  }
  

--- 1185,1192 -----
  writeerr()
  {
      perror ( ofname );
!     if ( zcat_flg == 0 )
! 	unlink ( ofname );
      exit ( 1 );
  }
  
***************
*** 1254,1260
  
  onintr ( )
  {
!     unlink ( ofname );
      exit ( 1 );
  }
  

--- 1255,1262 -----
  
  onintr ( )
  {
!     if ( zcat_flg == 0 )
! 	unlink ( ofname );
      exit ( 1 );
  }
  
***************
*** 1262,1268
  {
      if ( do_decomp == 1 ) 
      	fprintf ( stderr, "uncompress: corrupt input\n" );
!     unlink ( ofname );
      exit ( 1 );
  }
  

--- 1264,1271 -----
  {
      if ( do_decomp == 1 ) 
      	fprintf ( stderr, "uncompress: corrupt input\n" );
!     if ( zcat_flg == 0 )
! 	unlink ( ofname );
      exit ( 1 );
  }
  



More information about the Comp.sources.bugs mailing list