From: sysmark@helios.physics.utoronto.ca (Mark Bartelt)
Subject: tar portability problem
Reply-To: mark@cita.toronto.edu
Organization: University of Toronto Physics/Astronomy/CITA
Date: Wed, 8 Apr 1992 18:48:44 GMT

I'm surprised I haven't seen this one reported before.  (Maybe it has
been, but I managed to miss it.)  Anyway ...

Every so often (not frequently, but a couple times a year) I've gotten
a "directory checksum error" from tar when trying to use IRIX tar to
read a tar archive created under SunOS, or vice versa.  I now finally
understand the problem, thanks to a helpful tip from a friend.

(And no, I'm not talking about the byte-swapped vs non-byte-swapped
tape issue.  I think just about everyone who reads comp.sys.sgi is
aware of *that*.  And besides, this bug isn't limited to QIC tapes.)

All you have to do to create a nonportable tar archive is to include
a directory which has a file whose name contains a character with the
high bit set.  Granted, it isn't advisable to create files which have
such peculiar filenames (though perhaps as we move away from seven-bit
ASCII toward a more internationally-acceptable character set, and move
in the direction of eight-bit-cleanliness in things like the shell, it
may become less unusual to see almost any arbitrary bit pattern inside
a filename), but it is possible.  And leave it to some user to write a
program which will do exactly that.

The problem stems from the fact that (quoting my friend) ...

|                                                       tar's directory
| entry checksum is non-portable in the presence of filenames containing
| characters with the high bit set.  The original code for the checksum
| contains the expression
|         i += *cp;
| where cp of type `char *', and so the results will depend on whether
| characters are signed or unsigned.

So there's the problem:  IRIX's C compiler treats "char" as unsigned,
whereas SunOS's compiler treats it as signed.

Now I don't expect SGI to suddenly change either the way its compiler
works, or the checksum mechanism that IRIX tar uses by default.  (Just
think of all the problems either of those would generate!)

However, it would be nice to provide tar with a new option which would
tell it to use an alternate (i.e. "char" == "signed char") method for
computing checksums.

I generally disapprove of the widespread tendency to clutter up UNIX
tools with gratuitous features, but this seems like one that's needed,
there being no other way to easily deal with the problem.  Yes, IRIX's
tar does have an "e" option ("i" under SunOS) to tell it to ignore any
errors it encounters, and using it to read one of these incompatible
archives does make it continue, but *without* actually extracting the
"bad" files.

Note that to be maximally useful, this feature would have to be usable
both when creating archives (to be taken to non-IRIX machines), as well
as when reading archives grabbed from elsewhere.

Mark Bartelt                                              416/978-5619
Canadian Institute for                           mark@cita.toronto.edu
Theoretical Astrophysics                         mark@cita.utoronto.ca

"Clothes not busy being worn are busy drying." - Dylan, on laundry day
Newsgroups: comp.sys.sgi