tar needs to skip empty files in header info rather than exit

Andre Delafontaine andre.delafontaine at echostar.com
Tue May 1 14:39:44 MDT 2001


Package: busybox
Version: 0.51
Severity: normal

A tar created with GNU tar may contain valid empty entries, i.e. headers
containing empty file names. This happens e.g. when taring '/' and GNU
tar strips the leading '/' to make files relative:

admin at booter01.util:~$ tar --version
tar (GNU tar) 1.13.17
<snip>

admin at booter01.util:~$ tar cvf - / 2> /dev/null | od -vx | head -20
0000000 0000 0000 0000 0000 0000 0000 0000 0000
0000020 0000 0000 0000 0000 0000 0000 0000 0000
0000040 0000 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000
0000120 0000 0000 0000 0000 0000 0000 0000 0000
0000140 0000 0000 3030 3034 3537 0035 3030 3030
0000160 3030 0030 3030 3030 3030 0030 3030 3030
0000200 3030 3030 3030 0030 3730 3531 3034 3132
0000220 3437 0034 3030 3537 3436 2000 0035 0000
0000240 0000 0000 0000 0000 0000 0000 0000 0000
0000260 0000 0000 0000 0000 0000 0000 0000 0000
0000300 0000 0000 0000 0000 0000 0000 0000 0000
0000320 0000 0000 0000 0000 0000 0000 0000 0000
0000340 0000 0000 0000 0000 0000 0000 0000 0000
0000360 0000 0000 0000 0000 0000 0000 0000 0000
0000400 7500 7473 7261 2020 7200 6f6f 0074 0000
0000420 0000 0000 0000 0000 0000 0000 0000 0000
0000440 0000 0000 0000 0000 7200 6f6f 0074 0000
0000460 0000 0000 0000 0000 0000 0000 0000 0000

(the file name is the 1st entry in the header)


When busybox tar comes across one of these entries, it thinks it has met
the end of the file and jumps to 'endgame' in tar.c:readTarFile():

admin at booter01.util:/usr/src$ tar cf - / | busybox-0.51/busybox tar tvf
-
tar: Removing leading `/' from member names
Broken pipe

In the previous GNU tar case, this means the whole tar is ignored
without any error message.


This quick patch seems to fix the problem:

admin at booter01.util:/usr/src$ diff -u busybox-0.51-orig/tar.c
busybox-0.51
--- busybox-0.51-orig/tar.c	Wed Mar 28 16:57:51 2001
+++ busybox-0.51/tar.c	Tue May  1 13:19:46 2001
@@ -624,8 +624,8 @@
 				continue;
 			}
 		}
-		if ( *(header.name) == '\0' )
-				goto endgame;
+		if ( *(header.name) != '\0' )
+	    {
 		header.tarFd = tarFd;
 
 		/* Skip funky extra GNU headers that precede long files */
@@ -770,6 +770,7 @@
 				error_msg("Unknown file type '%c' in tar file", header.type);
 				close( tarFd);
 				return( FALSE);
+		}
 		}
 	}
 	close(tarFd);


Some alignment cleanup might help, although it would have made the patch
less readable.


Andre
-- 
             andre.delafontaine at echostar.com

  F20 DSS: BD75 66D9 5B2C 66CE 9158  BB27 B199 59CE D117 4E9F
   F16 RSA: F8 04 FE 50 02 B5 03 02  F6 87 C7 8D F9 2E B8 58

---------------------------------------
Received: (at 1163-close) by bugs.lineo.com; 1 May 2001 21:15:01 +0000


More information about the busybox mailing list