Subject: bin/867: /usr/bin/file breaks on tar's of . files.
To: None <gnats-admin@NetBSD.ORG>
From: None <cml@mindslayer.mother.com>
List: netbsd-bugs
Date: 03/12/1995 19:20:06
>Number:         867
>Category:       bin
>Synopsis:       /usr/bin/file breaks on tar's of . files.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 12 19:20:03 1995
>Originator:     Chris Lambertus
>Organization:
"	None"
>Release:        1.0 and -current
>Environment:
System: NetBSD mindslayer 1.0 NetBSD 1.0 (MINDSLAYER) #0: Sun Feb 5 02:35:23 PST 1995 root@mindslayer:/usr/src/sys/arch/i386/compile/MINDSLAYER i386


>Description:
	/usr/bin/file incorrectly reports tar archives when the first
	file in the archive starts with .  The . is cased as a troff
	document in ascmagic.c before the is_tar routine runs.
>How-To-Repeat:
	tar -cf foo.tar .profile
	file foo.tar
	foo.tar: troff or preprocessor input text
>Fix:
	Apply this patch which reorders the checks in ascmagic.c:

*** /usr/src/usr.bin/file/ascmagic.orig	Fri Apr  8 03:16:38 1994
--- /usr/src/usr.bin/file/ascmagic.c	Sun Mar 12 16:16:54 1995
***************
*** 52,58 ****
  	char *token;
  	register struct names *p;
  
! 	/* these are easy, do them first */
  
  	/*
  	 * for troff, look for . + letter + letter or .\";
--- 52,88 ----
  	char *token;
  	register struct names *p;
  
! 
! 	switch (is_tar(buf)) {
! 	case 1:
! 		ckfputs("tar archive", stdout);
! 		return 1;
! 	case 2:
! 		ckfputs("POSIX tar archive", stdout);
! 		return 1;
! 	}
! 
! 	if (i = is_compress(buf, &isblock)) {
! 		if (zflag) {
! 			unsigned char *newbuf;
! 			int newsize;
! 
! 			if (newsize = uncompress(buf, &newbuf, nbytes)) {
! 			    tryit(newbuf, newsize);
! 			    free(newbuf);
! 			}
! 			printf(" (%scompressed data - %d bits)",
! 				isblock ? "block " : "", i);
! 		}
! 	 	else printf("%scompressed data - %d bits",
! 			isblock ? "block " : "", i);
! 		return 1;
! 	}
! 
! 	for (i = 0; i < nbytes; i++) {
! 		if (!isascii(*(buf+i)))
! 			return 0;	/* not all ascii */
! 	}
  
  	/*
  	 * for troff, look for . + letter + letter or .\";
***************
*** 70,75 ****
--- 100,106 ----
  			return 1;
  		}
  	}
+ 
  	if ((*buf == 'c' || *buf == 'C') && 
  	    isascii(*(buf + 1)) && isspace(*(buf + 1))) {
  		ckfputs("fortran program text", stdout);
***************
*** 92,128 ****
  				return 1;
  			}
  		}
- 	}
- 
- 	switch (is_tar(buf)) {
- 	case 1:
- 		ckfputs("tar archive", stdout);
- 		return 1;
- 	case 2:
- 		ckfputs("POSIX tar archive", stdout);
- 		return 1;
- 	}
- 
- 	if (i = is_compress(buf, &isblock)) {
- 		if (zflag) {
- 			unsigned char *newbuf;
- 			int newsize;
- 
- 			if (newsize = uncompress(buf, &newbuf, nbytes)) {
- 			    tryit(newbuf, newsize);
- 			    free(newbuf);
- 			}
- 			printf(" (%scompressed data - %d bits)",
- 				isblock ? "block " : "", i);
- 		}
- 	 	else printf("%scompressed data - %d bits",
- 			isblock ? "block " : "", i);
- 		return 1;
- 	}
- 
- 	for (i = 0; i < nbytes; i++) {
- 		if (!isascii(*(buf+i)))
- 			return 0;	/* not all ascii */
  	}
  
  	/* all else fails, but it is ascii... */
--- 123,128 ----
>Audit-Trail:
>Unformatted: