Bug 38857

Summary: "file" command hangs when using "-z" option with very little compressed files
Product: Base System Reporter: Miguel Angel Vicente Serrano <unixroot>
Component: miscAssignee: David E. O'Brien <obrien>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Miguel Angel Vicente Serrano 2002-06-03 15:40:02 UTC
I compress a very little file using gzip with those commands:
echo aaaa > little ; gzip -9v little
The result is little.gz and when I use the command:
file -z little.gz
the process hangs, using almosr 99% of cpu, as shown on "top" command

Fix: 

to fix:

gzcat little.gz | file -
How-To-Repeat: echo aaaa > little
gzip -9v little
file -z little.gz     ======> process hangs
Comment 1 Peter Pentchev 2002-06-05 12:29:30 UTC
On Mon, Jun 03, 2002 at 07:36:17AM -0700, Miguel Angel Vicente Serrano wrote:
> 
> >Number:         38857
> >Category:       misc
> >Synopsis:       "file" command hangs when using "-z" option with very little compressed files
> >Originator:     Miguel Angel Vicente Serrano
> >Environment:
> 4.5 RELEASE
> >Description:
> I compress a very little file using gzip with those commands:
> echo aaaa > little ; gzip -9v little
> The result is little.gz and when I use the command:
> file -z little.gz
> the process hangs, using almosr 99% of cpu, as shown on "top" command
> >How-To-Repeat:
> echo aaaa > little
> gzip -9v little
> file -z little.gz     ======> process hangs
> >Fix:
> to fix:
> 
> gzcat little.gz | file -

Attached is a patch that fixes this problem; it is made against the
sources in the FreeBSD 5.0-CURRENT branch, but it applies cleanly
against both 4.5-RELEASE and 4.6-RC (today's -STABLE).

A note to David O'Brien, the maintainer of FreeBSD's file(1):
This patch is actually taken from Christos Zoulas's file-3.38; that is,
it may safely be vendor-imported, and the vendor impotr of the next
file(1) release will incorporate it with no problems.  I took the time
to check Christos's new versions right after I had come up with the
exact same fix for this issue :)

G'luck,
Peter

-- 
Peter Pentchev	roam@ringlet.net	roam@FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
This sentence claims to be an Epimenides paradox, but it is lying.

Index: src/contrib/file/compress.c
===================================================================
RCS file: /home/ncvs/src/contrib/file/compress.c,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 compress.c
--- src/contrib/file/compress.c	30 Jul 2001 03:09:43 -0000	1.1.1.3
+++ src/contrib/file/compress.c	5 Jun 2002 11:24:54 -0000
@@ -120,6 +120,8 @@
 			if (errno == EINTR)
 				continue;
 			return -1;
+		case 0:
+			return rn - n;
 		default:
 			n -= rv;
 			buf = ((char *)buf) + rv;
Comment 2 Peter Pentchev freebsd_committer freebsd_triage 2002-06-05 15:51:32 UTC
Responsible Changed
From-To: freebsd-bugs->obrien

Over to David O'Brien, the maintainer of file(1) in FreeBSD. 
David, I've included a patch in the audit tail, and it is also 
included verbatin in file-3.38; a vendor import of this patch 
should work just fine. 

I wonder if this could get into 4.6-RELEASE.. Probably not, 
but still.. :)
Comment 3 David E. O'Brien freebsd_committer freebsd_triage 2002-10-19 19:10:19 UTC
State Changed
From-To: open->closed

file(1) has been updated