summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ChangeLog36
-rw-r--r--INSTALL7
-rw-r--r--Makefile.in13
-rw-r--r--NEWS19
-rw-r--r--README77
-rwxr-xr-xconfigure12
-rw-r--r--create.cc306
-rw-r--r--doc/tarlz.141
-rw-r--r--doc/tarlz.info498
-rw-r--r--doc/tarlz.texi522
-rw-r--r--extract.cc398
-rw-r--r--main.cc121
-rw-r--r--tarlz.h70
-rwxr-xr-xtestsuite/check.sh489
-rw-r--r--testsuite/t155.tarbin0 -> 6144 bytes
-rw-r--r--testsuite/t155.tar.lzbin0 -> 579 bytes
-rw-r--r--testsuite/test3_bad3.tar.lzbin356 -> 356 bytes
-rw-r--r--testsuite/test3_bad4.tar.lzbin356 -> 356 bytes
-rw-r--r--testsuite/test3_dir.tar.lz (renamed from testsuite/test3a.tar.lz)bin358 -> 358 bytes
-rw-r--r--testsuite/test3_dot.tar.lzbin0 -> 349 bytes
-rw-r--r--testsuite/test_bad1.txt307
-rw-r--r--testsuite/test_bad1.txt.tarbin0 -> 17014 bytes
-rw-r--r--testsuite/test_bad1.txt.tar.lzbin0 -> 6000 bytes
-rw-r--r--testsuite/test_bad2.txt320
-rw-r--r--testsuite/test_bad2.txt.tar.lzbin0 -> 7495 bytes
-rw-r--r--testsuite/tlz_in_tar1.tarbin0 -> 2048 bytes
-rw-r--r--testsuite/tlz_in_tar2.tarbin0 -> 3072 bytes
-rw-r--r--testsuite/ug32chars.tar.lzbin0 -> 175 bytes
28 files changed, 2665 insertions, 571 deletions
diff --git a/ChangeLog b/ChangeLog
index a54be98..3e13c24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2018-12-16 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 0.8 released.
+ * Added new option '--anonymous' (--owner=root --group=root).
+ * extract.cc (decode): 'tarlz -xf foo ./bar' now extracts 'bar'.
+ * create.cc: Set to zero most fields in extended headers.
+ * tarlz.texi: Added new chapter 'Amendments to pax format'.
+
+2018-11-23 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 0.7 released.
+ * Added new option '--keep-damaged'.
+ * Added new option '--no-solid'.
+ * create.cc (archive_write): Minimize dictionary size.
+ * create.cc: Detect and skip archive in '-A', '-c' and '-r'.
+ * main.cc (show_version): Show the version of lzlib being used.
+
+2018-10-19 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 0.6 released.
+ * Added new option '-A, --concatenate'.
+ * Option '--ignore-crc' replaced with '--missing-crc'.
+ * create.cc (add_member): Test that uid, gid, mtime, devmajor
+ and devminor are in ustar range.
+ * configure: Accept appending to CXXFLAGS, 'CXXFLAGS+=OPTIONS'.
+ * Makefile.in: Use tarlz in target 'dist'.
+
+2018-09-29 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 0.5 released.
+ * Implemented simplified posix pax format.
+ * Implemented CRC32-C (Castagnoli) of the extended header data.
+ * Added new option '--ignore-crc'.
+ * Added missing #includes for major, minor and makedev.
+ * tarlz.texi: Documented the new archive format.
+
2018-04-23 Antonio Diaz Diaz <antonio@gnu.org>
* Version 0.4 released.
diff --git a/INSTALL b/INSTALL
index c05e8a8..680cacf 100644
--- a/INSTALL
+++ b/INSTALL
@@ -3,6 +3,9 @@ Requirements
You will need a C++ compiler and the lzlib compression library installed.
I use gcc 5.3.0 and 4.1.2, but the code should compile with any
standards compliant compiler.
+Lzlib must be version 1.0 or newer, but --keep-damaged requires lzlib
+1.11-rc2 or newer to recover as much data as possible from each damaged
+member.
Gcc is available at http://gcc.gnu.org.
Lzlib is available at http://www.nongnu.org/lzip/lzlib.html.
@@ -24,6 +27,10 @@ the main archive.
cd tarlz[version]
./configure
+ To link against a lzlib not installed in a standard place, use:
+
+ ./configure CPPFLAGS='-I<dir_of_lzlib.h>' LDFLAGS='-L<dir_of_liblz.a>'
+
3. Run make.
make
diff --git a/Makefile.in b/Makefile.in
index 1b94c12..fdcae2d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -101,7 +101,7 @@ uninstall-man :
dist : doc
ln -sf $(VPATH) $(DISTNAME)
- tar -Hustar --owner=root --group=root -cvf $(DISTNAME).tar \
+ tarlz --solid --owner=root --group=root -9cvf $(DISTNAME).tar.lz \
$(DISTNAME)/AUTHORS \
$(DISTNAME)/COPYING \
$(DISTNAME)/ChangeLog \
@@ -118,17 +118,24 @@ dist : doc
$(DISTNAME)/testsuite/check.sh \
$(DISTNAME)/testsuite/test.txt \
$(DISTNAME)/testsuite/test.txt.tar \
+ $(DISTNAME)/testsuite/test_bad1.txt.tar \
+ $(DISTNAME)/testsuite/test_bad[12].txt \
+ $(DISTNAME)/testsuite/t155.tar \
$(DISTNAME)/testsuite/test3.tar \
$(DISTNAME)/testsuite/test3_bad[1-5].tar \
$(DISTNAME)/testsuite/test.txt.lz \
$(DISTNAME)/testsuite/test.txt.tar.lz \
+ $(DISTNAME)/testsuite/test_bad[12].txt.tar.lz \
$(DISTNAME)/testsuite/test3.tar.lz \
- $(DISTNAME)/testsuite/test3a.tar.lz \
+ $(DISTNAME)/testsuite/tlz_in_tar[12].tar \
+ $(DISTNAME)/testsuite/test3_dir.tar.lz \
+ $(DISTNAME)/testsuite/test3_dot.tar.lz \
+ $(DISTNAME)/testsuite/t155.tar.lz \
$(DISTNAME)/testsuite/test3_bad[1-6].tar.lz \
$(DISTNAME)/testsuite/dotdot[1-5].tar.lz \
+ $(DISTNAME)/testsuite/ug32chars.tar.lz \
$(DISTNAME)/testsuite/eof.tar.lz
rm -f $(DISTNAME)
- lzip -v -9 $(DISTNAME).tar
clean :
-rm -f $(progname) $(objs)
diff --git a/NEWS b/NEWS
index 815ed45..2dcbb9b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,18 @@
-Changes in version 0.4:
+Changes in version 0.8:
-Some missing #includes have been fixed.
+The new option '--anonymous', equivalent to '--owner=root --group=root', has
+been added.
-Open files in binary mode on OS2.
+On extraction and listing, tarlz now removes leading './' strings also from
+member names given in the command line. 'tarlz -xf foo ./bar' now extracts
+member 'bar' from archive 'foo'. (Reported by Viktor Sergiienko in the
+bug-tar mailing list).
+
+Tarlz now writes extended headers with all fields zeroed except size,
+chksum, typeflag, magic and version. This prevents old tar programs from
+extracting the extended records as a file in the wrong place (with a
+truncated filename). Tarlz now also sets to zero those fields of the ustar
+header overridden by extended records.
+
+The chapter 'Amendments to pax format', explaining the reasons for the
+differences with the pax format, has been added.
diff --git a/README b/README
index bafec18..44edeea 100644
--- a/README
+++ b/README
@@ -1,36 +1,16 @@
Description
-Tarlz is a small and simple implementation of the tar archiver. By
-default tarlz creates, lists and extracts archives in the 'ustar' format
-compressed with lzip on a per file basis. Tarlz can append files to the
-end of such compressed archives.
-
-Each tar member is compressed in its own lzip member, as well as the
-end-of-file blocks. This same method works for any tar format (gnu,
-ustar, posix) and is fully backward compatible with standard tar tools
-like GNU tar, which treat the resulting multimember tar.lz archive like
-any other tar.lz archive.
+Tarlz is a small and simple implementation of the tar archiver. By default
+tarlz creates, lists and extracts archives in a simplified posix pax format
+compressed with lzip on a per file basis. Each tar member is compressed in
+its own lzip member, as well as the end-of-file blocks. This method is fully
+backward compatible with standard tar tools like GNU tar, which treat the
+resulting multimember tar.lz archive like any other tar.lz archive. Tarlz
+can append files to the end of such compressed archives.
Tarlz can create tar archives with four levels of compression
granularity; per file, per directory, appendable solid, and solid.
-Tarlz is intended as a showcase project for the maintainers of real tar
-programs to evaluate the format and perhaps implement it in their tools.
-
-The diagram below shows the correspondence between tar members (formed
-by a header plus optional data) in the tar archive and lzip members in
-the resulting multimember tar.lz archive:
-
-tar
-+========+======+========+======+========+======+========+
-| header | data | header | data | header | data | eof |
-+========+======+========+======+========+======+========+
-
-tar.lz
-+===============+===============+===============+========+
-| member | member | member | member |
-+===============+===============+===============+========+
-
Of course, compressing each file (or each directory) individually is
less efficient than compressing the whole tar archive, but it has the
following advantages:
@@ -38,19 +18,56 @@ following advantages:
* The resulting multimember tar.lz archive can be decompressed in
parallel with plzip, multiplying the decompression speed.
- * New members can be appended to the archive (by removing the eof
+ * New members can be appended to the archive (by removing the EOF
member) just like to an uncompressed tar archive.
* It is a safe posix-style backup format. In case of corruption,
tarlz can extract all the undamaged members from the tar.lz
archive, skipping over the damaged members, just like the standard
- (uncompressed) tar. Moreover, lziprecover can be used to recover at
- least part of the contents of the damaged members.
+ (uncompressed) tar. Moreover, the option '--keep-damaged' can be
+ used to recover as much data as possible from each damaged member,
+ and lziprecover can be used to recover some of the damaged members.
* A multimember tar.lz archive is usually smaller than the
corresponding solidly compressed tar.gz archive, except when
individually compressing files smaller than about 32 KiB.
+Note that the posix pax format has a serious flaw. The metadata stored
+in pax extended records are not protected by any kind of check sequence.
+Corruption in a long filename may cause the extraction of the file in the
+wrong place without warning. Corruption in a long file size may cause the
+truncation of the file or the appending of garbage to the file, both
+followed by a spurious warning about a corrupt header far from the place
+of the undetected corruption.
+
+Metadata like filename and file size must be always protected in an archive
+format because of the adverse effects of undetected corruption in them,
+potentially much worse that undetected corruption in the data. Even more so
+in the case of pax because the amount of metadata it stores is potentially
+large, making undetected corruption more probable.
+
+Because of the above, tarlz protects the extended records with a CRC in
+a way compatible with standard tar tools.
+
+Tarlz does not understand other tar formats like gnu, oldgnu, star or v7.
+
+Tarlz is intended as a showcase project for the maintainers of real tar
+programs to evaluate the format and perhaps implement it in their tools.
+
+The diagram below shows the correspondence between each tar member
+(formed by one or two headers plus optional data) in the tar archive and
+each lzip member in the resulting multimember tar.lz archive:
+
+tar
++========+======+=================+===============+========+======+========+
+| header | data | extended header | extended data | header | data | EOF |
++========+======+=================+===============+========+======+========+
+
+tar.lz
++===============+=================================================+========+
+| member | member | member |
++===============+=================================================+========+
+
Copyright (C) 2013-2018 Antonio Diaz Diaz.
diff --git a/configure b/configure
index a8a5d34..239d732 100755
--- a/configure
+++ b/configure
@@ -6,7 +6,7 @@
# to copy, distribute and modify it.
pkgname=tarlz
-pkgversion=0.4
+pkgversion=0.8
progname=tarlz
srctrigger=doc/${pkgname}.texi
@@ -70,6 +70,7 @@ while [ $# != 0 ] ; do
echo " CXX=COMPILER C++ compiler to use [${CXX}]"
echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]"
echo " CXXFLAGS=OPTIONS command line options for the C++ compiler [${CXXFLAGS}]"
+ echo " CXXFLAGS+=OPTIONS append options to the current value of CXXFLAGS"
echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]"
echo
exit 0 ;;
@@ -93,10 +94,11 @@ while [ $# != 0 ] ; do
--mandir=*) mandir=${optarg} ;;
--no-create) no_create=yes ;;
- CXX=*) CXX=${optarg} ;;
- CPPFLAGS=*) CPPFLAGS=${optarg} ;;
- CXXFLAGS=*) CXXFLAGS=${optarg} ;;
- LDFLAGS=*) LDFLAGS=${optarg} ;;
+ CXX=*) CXX=${optarg} ;;
+ CPPFLAGS=*) CPPFLAGS=${optarg} ;;
+ CXXFLAGS=*) CXXFLAGS=${optarg} ;;
+ CXXFLAGS+=*) CXXFLAGS="${CXXFLAGS} ${optarg}" ;;
+ LDFLAGS=*) LDFLAGS=${optarg} ;;
--*)
echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;;
diff --git a/create.cc b/create.cc
index c5bed25..ba7d10a 100644
--- a/create.cc
+++ b/create.cc
@@ -28,6 +28,10 @@
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#if defined(__GNU_LIBRARY__)
+#include <sys/sysmacros.h> // for major, minor
+#endif
#include <ftw.h>
#include <grp.h>
#include <pwd.h>
@@ -37,6 +41,9 @@
#include "lzip.h"
#include "tarlz.h"
+
+const CRC32C crc32c;
+
int cl_owner = -1; // global vars needed by add_member
int cl_group = -1;
int cl_solid = 0; // 1 = dsolid, 2 = asolid, 3 = solid
@@ -44,6 +51,7 @@ int cl_solid = 0; // 1 = dsolid, 2 = asolid, 3 = solid
namespace {
LZ_Encoder * encoder = 0; // local vars needed by add_member
+const char * archive_namep = 0;
int outfd = -1;
int gretval = 0;
@@ -55,31 +63,67 @@ int seek_read( const int fd, uint8_t * const buf, const int size,
return 0;
}
-// Check archive type, remove EOF blocks, and leave outfd file pos at EOF
-bool check_appendable()
+// infd and outfd can refer to the same file if copying to a lower file
+// position or if source and destination blocks don't overlap.
+// max_size < 0 means no size limit.
+bool copy_file( const int infd, const int outfd, const long long max_size = -1 )
+ {
+ const int buffer_size = 65536;
+ // remaining number of bytes to copy
+ long long rest = ( ( max_size >= 0 ) ? max_size : buffer_size );
+ long long copied_size = 0;
+ uint8_t * const buffer = new uint8_t[buffer_size];
+ bool error = false;
+
+ while( rest > 0 )
+ {
+ const int size = std::min( (long long)buffer_size, rest );
+ if( max_size >= 0 ) rest -= size;
+ const int rd = readblock( infd, buffer, size );
+ if( rd != size && errno )
+ { show_error( "Error reading input file", errno ); error = true; break; }
+ if( rd > 0 )
+ {
+ const int wr = writeblock( outfd, buffer, rd );
+ if( wr != rd )
+ { show_error( "Error writing output file", errno );
+ error = true; break; }
+ copied_size += rd;
+ }
+ if( rd < size ) break; // EOF
+ }
+ delete[] buffer;
+ return ( !error && ( max_size < 0 || copied_size == max_size ) );
+ }
+
+
+/* Check archive type. If success, leave fd file pos at 0.
+ If remove_eof, leave fd file pos at beginning of the EOF blocks. */
+bool check_appendable( const int fd, const bool remove_eof )
{
struct stat st;
- if( fstat( outfd, &st ) != 0 || !S_ISREG( st.st_mode ) ) return false;
- uint8_t buf[header_size];
- int rd = readblock( outfd, buf, header_size );
+ if( fstat( fd, &st ) != 0 || !S_ISREG( st.st_mode ) ) return false;
+ if( lseek( fd, 0, SEEK_SET ) != 0 ) return false;
+ enum { bufsize = header_size + ( header_size / 8 ) };
+ uint8_t buf[bufsize];
+ int rd = readblock( fd, buf, bufsize );
if( rd == 0 && errno == 0 ) return true; // append to empty archive
- if( rd < min_member_size || ( rd != header_size && errno ) ) return false;
- const Lzip_header * const p = (Lzip_header *)buf; // shut up gcc
+ if( rd < min_member_size || ( rd != bufsize && errno ) ) return false;
+ const Lzip_header * const p = (const Lzip_header *)buf; // shut up gcc
if( !p->verify_magic() ) return false;
LZ_Decoder * decoder = LZ_decompress_open(); // decompress first header
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok ||
LZ_decompress_write( decoder, buf, rd ) != rd ||
- ( rd = LZ_decompress_read( decoder, buf, header_size ) ) <
- magic_o + magic_l )
+ ( rd = LZ_decompress_read( decoder, buf, header_size ) ) != header_size )
{ LZ_decompress_close( decoder ); return false; }
LZ_decompress_close( decoder );
const bool maybe_eof = ( buf[0] == 0 );
if( !verify_ustar_chksum( buf ) && !maybe_eof ) return false;
- const long long end = lseek( outfd, 0, SEEK_END );
+ const long long end = lseek( fd, 0, SEEK_END );
if( end < min_member_size ) return false;
Lzip_trailer trailer;
- if( seek_read( outfd, trailer.data, Lzip_trailer::size,
+ if( seek_read( fd, trailer.data, Lzip_trailer::size,
end - Lzip_trailer::size ) != Lzip_trailer::size )
return false;
const long long member_size = trailer.member_size();
@@ -87,9 +131,8 @@ bool check_appendable()
( maybe_eof && member_size != end ) ) return false;
Lzip_header header;
- if( seek_read( outfd, header.data, Lzip_header::size,
- end - member_size ) != Lzip_header::size )
- return false;
+ if( seek_read( fd, header.data, Lzip_header::size,
+ end - member_size ) != Lzip_header::size ) return false;
if( !header.verify_magic() || !isvalid_ds( header.dictionary_size() ) )
return false;
@@ -102,12 +145,33 @@ bool check_appendable()
crc ^= 0xFFFFFFFFU;
if( crc != data_crc ) return false;
- if( lseek( outfd, end - member_size, SEEK_SET ) != end - member_size ||
- ftruncate( outfd, end - member_size ) != 0 ) return false;
- return true;
+ const long long pos = remove_eof ? end - member_size : 0;
+ return ( lseek( fd, pos, SEEK_SET ) == pos );
}
+class File_is_archive
+ {
+ dev_t archive_dev;
+ ino_t archive_ino;
+ bool initialized;
+public:
+ File_is_archive() : initialized( false ) {}
+ bool init()
+ {
+ struct stat st;
+ if( fstat( outfd, &st ) != 0 ) return false;
+ if( S_ISREG( st.st_mode ) )
+ { archive_dev = st.st_dev; archive_ino = st.st_ino; initialized = true; }
+ return true;
+ }
+ bool operator()( const struct stat & st ) const
+ {
+ return initialized && archive_dev == st.st_dev && archive_ino == st.st_ino;
+ }
+ } file_is_archive;
+
+
bool archive_write( const uint8_t * const buf, const int size )
{
if( !encoder ) // uncompressed
@@ -121,9 +185,10 @@ bool archive_write( const uint8_t * const buf, const int size )
const int wr = LZ_compress_write( encoder, buf + sz, size - sz );
if( wr < 0 ) internal_error( "library error (LZ_compress_write)." );
sz += wr;
+ if( sz >= size && size > 0 ) break; // minimize dictionary size
const int rd = LZ_compress_read( encoder, obuf, obuf_size );
if( rd < 0 ) internal_error( "library error (LZ_compress_read)." );
- if( rd == 0 && sz == size ) break;
+ if( rd == 0 && sz >= size ) break;
if( writeblock( outfd, obuf, rd ) != rd ) return false;
}
if( LZ_compress_finished( encoder ) == 1 &&
@@ -133,11 +198,98 @@ bool archive_write( const uint8_t * const buf, const int size )
}
+void init_tar_header( Tar_header header ) // set magic and version
+ {
+ std::memset( header, 0, header_size );
+ std::memcpy( header + magic_o, ustar_magic, magic_l - 1 );
+ header[version_o] = header[version_o+1] = '0';
+ }
+
+
+unsigned char xdigit( const unsigned value )
+ {
+ if( value <= 9 ) return '0' + value;
+ if( value <= 15 ) return 'A' + value - 10;
+ return 0;
+ }
+
+void print_hex( char * const buf, int size, unsigned long long num )
+ {
+ while( --size >= 0 ) { buf[size] = xdigit( num & 0x0F ); num >>= 4; }
+ }
+
void print_octal( char * const buf, int size, unsigned long long num )
{
while( --size >= 0 ) { buf[size] = '0' + ( num % 8 ); num /= 8; }
}
+unsigned decimal_digits( unsigned long long value )
+ {
+ unsigned digits = 1;
+ while( value >= 10 ) { value /= 10; ++digits; }
+ return digits;
+ }
+
+unsigned long long record_size( const unsigned keyword_size,
+ const unsigned long long value_size )
+ {
+ // size = ' ' + keyword + '=' + value + '\n'
+ const unsigned long long size = 1 + keyword_size + 1 + value_size + 1;
+ const unsigned d1 = decimal_digits( size );
+ return decimal_digits( d1 + size ) + size;
+ }
+
+bool write_extended( const Extended & extended )
+ {
+ const int path_rec = extended.path.size() ?
+ record_size( 4, extended.path.size() ) : 0;
+ const int lpath_rec = extended.linkpath.size() ?
+ record_size( 8, extended.linkpath.size() ) : 0;
+ const int size_rec = ( extended.size > 0 ) ?
+ record_size( 4, decimal_digits( extended.size ) ) : 0;
+ const unsigned long long edsize = path_rec + lpath_rec + size_rec + 22;
+ const unsigned long long bufsize = round_up( edsize );
+ if( edsize >= 1ULL << 33 ) return false; // too much extended data
+ if( bufsize == 0 ) return edsize == 0; // overflow or no extended data
+ char * const buf = new char[bufsize+1]; // extended records buffer
+ unsigned long long pos = path_rec; // goto can't cross this
+ if( path_rec && snprintf( buf, path_rec + 1, "%d path=%s\n",
+ path_rec, extended.path.c_str() ) != path_rec )
+ goto error;
+ if( lpath_rec && snprintf( buf + pos, lpath_rec + 1, "%d linkpath=%s\n",
+ lpath_rec, extended.linkpath.c_str() ) != lpath_rec )
+ goto error;
+ pos += lpath_rec;
+ if( size_rec && snprintf( buf + pos, size_rec + 1, "%d size=%llu\n",
+ size_rec, extended.size ) != size_rec )
+ goto error;
+ pos += size_rec;
+ if( snprintf( buf + pos, 23, "22 GNU.crc32=00000000\n" ) != 22 ) goto error;
+ pos += 22;
+ if( pos != edsize ) goto error;
+ print_hex( buf + edsize - 9, 8,
+ crc32c.windowed_crc( (const uint8_t *)buf, edsize - 9, edsize ) );
+ std::memset( buf + edsize, 0, bufsize - edsize ); // wipe padding
+ Tar_header header; // extended header
+ init_tar_header( header );
+ header[typeflag_o] = tf_extended; // fill only required fields
+ print_octal( header + size_o, size_l - 1, edsize );
+ print_octal( header + chksum_o, chksum_l - 1,
+ ustar_chksum( (const uint8_t *)header ) );
+ if( !archive_write( (const uint8_t *)header, header_size ) ) goto error;
+ for( pos = 0; pos < bufsize; ) // write extended records to archive
+ {
+ int size = std::min( bufsize - pos, 1ULL << 20 );
+ if( !archive_write( (const uint8_t *)buf + pos, size ) ) goto error;
+ pos += size;
+ }
+ delete[] buf;
+ return true;
+error:
+ delete[] buf;
+ return false;
+ }
+
const char * remove_leading_dotdot( const char * const filename )
{
@@ -164,24 +316,31 @@ const char * remove_leading_dotdot( const char * const filename )
}
-bool split_name( const char * const filename, Tar_header header )
+// Return true if filename fits in the ustar header.
+bool store_name( const char * const filename, Extended & extended,
+ Tar_header header )
{
const char * const stored_name = remove_leading_dotdot( filename );
const int len = std::strlen( stored_name );
enum { max_len = prefix_l + 1 + name_l }; // prefix + '/' + name
+
+ // first try storing filename in the ustar header
if( len <= name_l ) // stored_name fits in name
{ std::memcpy( header + name_o, stored_name, len ); return true; }
if( len <= max_len ) // find shortest prefix
for( int i = len - name_l - 1; i < len && i <= prefix_l; ++i )
- if( stored_name[i] == '/' )
+ if( stored_name[i] == '/' ) // stored_name can be split
{
std::memcpy( header + name_o, stored_name + i + 1, len - i - 1 );
std::memcpy( header + prefix_o, stored_name, i );
return true;
}
+ // store filename in extended record, leave name zeroed in ustar header
+ extended.path = stored_name;
return false;
}
+
int add_member( const char * const filename, const struct stat *,
const int flag, struct FTW * )
{
@@ -189,11 +348,13 @@ int add_member( const char * const filename, const struct stat *,
if( lstat( filename, &st ) != 0 )
{ show_file_error( filename, "Can't stat input file", errno );
gretval = 1; return 0; }
+ if( file_is_archive( st ) )
+ { show_file_error( archive_namep, "File is the archive; not dumped." );
+ return 0; }
+ Extended extended; // metadata for extended records
Tar_header header;
- std::memset( header, 0, header_size );
- if( !split_name( filename, header ) )
- { show_file_error( filename, "File name is too long." );
- gretval = 2; return 0; }
+ init_tar_header( header );
+ store_name( filename, extended, header );
const mode_t mode = st.st_mode;
print_octal( header + mode_o, mode_l - 1,
@@ -201,10 +362,17 @@ int add_member( const char * const filename, const struct stat *,
S_IRWXU | S_IRWXG | S_IRWXO ) );
const uid_t uid = ( cl_owner >= 0 ) ? (uid_t)cl_owner : st.st_uid;
const gid_t gid = ( cl_group >= 0 ) ? (gid_t)cl_group : st.st_gid;
+ if( uid >= 2 << 20 || gid >= 2 << 20 )
+ { show_file_error( filename, "uid or gid is larger than 2_097_151." );
+ gretval = 1; return 0; }
print_octal( header + uid_o, uid_l - 1, uid );
print_octal( header + gid_o, gid_l - 1, gid );
+ const long long mtime = st.st_mtime; // shut up gcc
+ if( mtime < 0 || mtime >= 1LL << 33 )
+ { show_file_error( filename, "mtime is out of ustar range [0, 8_589_934_591]." );
+ gretval = 1; return 0; }
+ print_octal( header + mtime_o, mtime_l - 1, mtime );
unsigned long long file_size = 0;
- print_octal( header + mtime_o, mtime_l - 1, st.st_mtime );
Typeflag typeflag;
if( S_ISREG( mode ) ) { typeflag = tf_regular; file_size = st.st_size; }
else if( S_ISDIR( mode ) )
@@ -217,16 +385,26 @@ int add_member( const char * const filename, const struct stat *,
else if( S_ISLNK( mode ) )
{
typeflag = tf_symlink;
- if( st.st_size > linkname_l ||
- readlink( filename, header + linkname_o, linkname_l ) != st.st_size )
+ long len;
+ if( st.st_size <= linkname_l )
+ len = readlink( filename, header + linkname_o, linkname_l );
+ else
{
- show_file_error( filename, "Link destination name is too long." );
- gretval = 2; return 0;
+ char * const buf = new char[st.st_size+1];
+ len = readlink( filename, buf, st.st_size );
+ if( len == st.st_size ) { buf[len] = 0; extended.linkpath = buf; }
+ delete[] buf;
}
+ if( len != st.st_size )
+ { show_file_error( filename, "Error reading link", (len < 0) ? errno : 0 );
+ gretval = 1; return 0; }
}
else if( S_ISCHR( mode ) || S_ISBLK( mode ) )
{
typeflag = S_ISCHR( mode ) ? tf_chardev : tf_blockdev;
+ if( major( st.st_dev ) >= 2 << 20 || minor( st.st_dev ) >= 2 << 20 )
+ { show_file_error( filename, "devmajor or devminor is larger than 2_097_151." );
+ gretval = 1; return 0; }
print_octal( header + devmajor_o, devmajor_l - 1, major( st.st_dev ) );
print_octal( header + devminor_o, devminor_l - 1, minor( st.st_dev ) );
}
@@ -234,22 +412,23 @@ int add_member( const char * const filename, const struct stat *,
else { show_file_error( filename, "Unknown file type." );
gretval = 2; return 0; }
header[typeflag_o] = typeflag;
- std::memcpy( header + magic_o, ustar_magic, magic_l - 1 );
- header[version_o] = header[version_o+1] = '0';
const struct passwd * const pw = getpwuid( uid );
if( pw && pw->pw_name )
std::strncpy( header + uname_o, pw->pw_name, uname_l - 1 );
const struct group * const gr = getgrgid( gid );
if( gr && gr->gr_name )
std::strncpy( header + gname_o, gr->gr_name, gname_l - 1 );
- print_octal( header + size_o, size_l - 1, file_size );
+ if( file_size >= 1ULL << 33 ) extended.size = file_size;
+ else print_octal( header + size_o, size_l - 1, file_size );
print_octal( header + chksum_o, chksum_l - 1,
ustar_chksum( (const uint8_t *)header ) );
const int infd = file_size ? open_instream( filename ) : -1;
if( file_size && infd < 0 ) { gretval = 1; return 0; }
+ if( !extended.empty() && !write_extended( extended ) )
+ { show_error( "Error writing extended header", errno ); return 1; }
if( !archive_write( (const uint8_t *)header, header_size ) )
- { show_error( "Error writing archive header", errno ); return 1; }
+ { show_error( "Error writing ustar header", errno ); return 1; }
if( file_size )
{
enum { bufsize = 32 * header_size };
@@ -304,6 +483,49 @@ bool verify_ustar_chksum( const uint8_t * const buf )
ustar_chksum( buf ) == strtoul( (const char *)buf + chksum_o, 0, 8 ) ); }
+int concatenate( const std::string & archive_name, const Arg_parser & parser,
+ const int filenames )
+ {
+ if( !filenames )
+ { if( verbosity >= 1 ) show_error( "Nothing to concatenate." ); return 0; }
+ if( archive_name.empty() )
+ { show_error( "'--concatenate' is incompatible with '-f -'.", 0, true );
+ return 1; }
+ if( ( outfd = open_outstream( archive_name, false ) ) < 0 ) return 1;
+ if( !file_is_archive.init() )
+ { show_file_error( archive_name.c_str(), "Can't stat", errno ); return 1; }
+
+ int retval = 0;
+ for( int i = 0; i < parser.arguments(); ++i ) // copy archives
+ {
+ if( parser.code( i ) ) continue; // skip options
+ const char * const filename = parser.argument( i ).c_str();
+ const int infd = open_instream( filename );
+ if( infd < 0 )
+ { show_file_error( filename, "Can't open input file", errno );
+ retval = 1; break; }
+ if( !check_appendable( infd, false ) )
+ { show_file_error( filename, "Not an appendable tar.lz archive." );
+ close( infd ); retval = 2; break; }
+ struct stat st;
+ if( fstat( infd, &st ) == 0 && file_is_archive( st ) )
+ { show_file_error( filename, "File is the archive; not concatenated." );
+ close( infd ); continue; }
+ if( !check_appendable( outfd, true ) )
+ { show_error( "This does not look like an appendable tar.lz archive." );
+ close( infd ); retval = 2; break; }
+ if( !copy_file( infd, outfd ) || close( infd ) != 0 )
+ { show_file_error( filename, "Error copying archive", errno );
+ retval = 1; break; }
+ if( verbosity >= 1 ) std::fprintf( stderr, "%s\n", filename );
+ }
+
+ if( close( outfd ) != 0 && !retval )
+ { show_error( "Error closing archive", errno ); retval = 1; }
+ return retval;
+ }
+
+
int encode( const std::string & archive_name, const Arg_parser & parser,
const int filenames, const int level, const bool append )
{
@@ -345,11 +567,15 @@ int encode( const std::string & archive_name, const Arg_parser & parser,
{ show_error( "'--append' is incompatible with '--uncompressed'.", 0, true );
return 1; }
if( ( outfd = open_outstream( archive_name, false ) ) < 0 ) return 1;
- if( !check_appendable() )
+ if( !check_appendable( outfd, true ) )
{ show_error( "This does not look like an appendable tar.lz archive." );
return 2; }
}
+ archive_namep = archive_name.size() ? archive_name.c_str() : "(stdout)";
+ if( !file_is_archive.init() )
+ { show_file_error( archive_namep, "Can't stat", errno ); return 1; }
+
if( compressed )
{
encoder = LZ_compress_open( option_mapping[level].dictionary_size,
@@ -365,7 +591,6 @@ int encode( const std::string & archive_name, const Arg_parser & parser,
}
int retval = 0;
- std::string deslashed; // arg without trailing slashes
for( int i = 0; i < parser.arguments(); ++i ) // write members
{
const int code = parser.code( i );
@@ -375,6 +600,7 @@ int encode( const std::string & archive_name, const Arg_parser & parser,
{ show_file_error( filename, "Error changing working directory", errno );
retval = 1; break; }
if( code ) continue; // skip options
+ std::string deslashed; // arg without trailing slashes
unsigned len = arg.size();
while( len > 1 && arg[len-1] == '/' ) --len;
if( len < arg.size() )
@@ -391,16 +617,18 @@ int encode( const std::string & archive_name, const Arg_parser & parser,
if( !retval ) // write End-Of-Archive records
{
- uint8_t buf[header_size];
- std::memset( buf, 0, header_size );
+ enum { bufsize = 2 * header_size };
+ uint8_t buf[bufsize];
+ std::memset( buf, 0, bufsize );
if( encoder && cl_solid == 2 && !archive_write( 0, 0 ) ) // flush encoder
{ show_error( "Error flushing encoder", errno ); retval = 1; }
- else if( !archive_write( buf, header_size ) ||
- !archive_write( buf, header_size ) ||
+ else if( !archive_write( buf, bufsize ) ||
( encoder && !archive_write( 0, 0 ) ) ) // flush encoder
{ show_error( "Error writing end-of-archive blocks", errno );
retval = 1; }
}
+ if( encoder && LZ_compress_close( encoder ) < 0 )
+ { show_error( "LZ_compress_close failed." ); retval = 1; }
if( close( outfd ) != 0 && !retval )
{ show_error( "Error closing archive", errno ); retval = 1; }
if( retval && archive_name.size() && !append )
diff --git a/doc/tarlz.1 b/doc/tarlz.1
index 6b685c5..906fee0 100644
--- a/doc/tarlz.1
+++ b/doc/tarlz.1
@@ -1,12 +1,25 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1.
-.TH TARLZ "1" "April 2018" "tarlz 0.4" "User Commands"
+.TH TARLZ "1" "December 2018" "tarlz 0.8" "User Commands"
.SH NAME
tarlz \- creates tar archives with multimember lzip compression
.SH SYNOPSIS
.B tarlz
[\fI\,options\/\fR] [\fI\,files\/\fR]
.SH DESCRIPTION
-Tarlz \- Archiver with multimember lzip compression.
+Tarlz is a small and simple implementation of the tar archiver. By default
+tarlz creates, lists and extracts archives in a simplified posix pax format
+compressed with lzip on a per file basis. Each tar member is compressed in
+its own lzip member, as well as the end\-of\-file blocks. This method is fully
+backward compatible with standard tar tools like GNU tar, which treat the
+resulting multimember tar.lz archive like any other tar.lz archive. Tarlz
+can append files to the end of such compressed archives.
+.PP
+The tarlz file format is a safe posix\-style backup format. In case of
+corruption, tarlz can extract all the undamaged members from the tar.lz
+archive, skipping over the damaged members, just like the standard
+(uncompressed) tar. Moreover, the option '\-\-keep\-damaged' can be used to
+recover as much data as possible from each damaged member, and lziprecover
+can be used to recover some of the damaged members.
.SH OPTIONS
.TP
\fB\-h\fR, \fB\-\-help\fR
@@ -15,6 +28,9 @@ display this help and exit
\fB\-V\fR, \fB\-\-version\fR
output version information and exit
.TP
+\fB\-A\fR, \fB\-\-concatenate\fR
+append tar.lz archives to the end of an archive
+.TP
\fB\-c\fR, \fB\-\-create\fR
create a new archive
.TP
@@ -48,17 +64,29 @@ create solidly compressed appendable archive
\fB\-\-dsolid\fR
create per\-directory compressed archive
.TP
+\fB\-\-no\-solid\fR
+create per\-file compressed archive (default)
+.TP
\fB\-\-solid\fR
create solidly compressed archive
.TP
-\fB\-\-group=\fR<group>
-use <group> name/id for added files
+\fB\-\-anonymous\fR
+equivalent to '\-\-owner=root \fB\-\-group\fR=\fI\,root\/\fR'
.TP
\fB\-\-owner=\fR<owner>
-use <owner> name/id for added files
+use <owner> name/ID for files added
+.TP
+\fB\-\-group=\fR<group>
+use <group> name/ID for files added
+.TP
+\fB\-\-keep\-damaged\fR
+don't delete partially extracted files
+.TP
+\fB\-\-missing\-crc\fR
+exit with error status if missing extended CRC
.TP
\fB\-\-uncompressed\fR
-don't compress the created archive
+don't compress the archive created
.PP
Exit status: 0 for a normal exit, 1 for environmental problems (file
not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or
@@ -70,6 +98,7 @@ Report bugs to lzip\-bug@nongnu.org
Tarlz home page: http://www.nongnu.org/lzip/tarlz.html
.SH COPYRIGHT
Copyright \(co 2018 Antonio Diaz Diaz.
+Using lzlib 1.11\-rc2
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
.br
This is free software: you are free to change and redistribute it.
diff --git a/doc/tarlz.info b/doc/tarlz.info
index 140336b..d6d17d0 100644
--- a/doc/tarlz.info
+++ b/doc/tarlz.info
@@ -11,15 +11,17 @@ File: tarlz.info, Node: Top, Next: Introduction, Up: (dir)
Tarlz Manual
************
-This manual is for Tarlz (version 0.4, 23 April 2018).
+This manual is for Tarlz (version 0.8, 16 December 2018).
* Menu:
-* Introduction:: Purpose and features of tarlz
-* Invoking tarlz:: Command line interface
-* Examples:: A small tutorial with examples
-* Problems:: Reporting bugs
-* Concept index:: Index of concepts
+* Introduction:: Purpose and features of tarlz
+* Invoking tarlz:: Command line interface
+* File format:: Detailed format of the compressed archive
+* Amendments to pax format:: The reasons for the differences with pax
+* Examples:: A small tutorial with examples
+* Problems:: Reporting bugs
+* Concept index:: Index of concepts
Copyright (C) 2013-2018 Antonio Diaz Diaz.
@@ -34,38 +36,17 @@ File: tarlz.info, Node: Introduction, Next: Invoking tarlz, Prev: Top, Up: T
**************
Tarlz is a small and simple implementation of the tar archiver. By
-default tarlz creates, lists and extracts archives in the 'ustar' format
-compressed with lzip on a per file basis. Tarlz can append files to the
-end of such compressed archives.
-
- Each tar member is compressed in its own lzip member, as well as the
-end-of-file blocks. This same method works for any tar format (gnu,
-ustar, posix) and is fully backward compatible with standard tar tools
+default tarlz creates, lists and extracts archives in a simplified
+posix pax format compressed with lzip on a per file basis. Each tar
+member is compressed in its own lzip member, as well as the end-of-file
+blocks. This method is fully backward compatible with standard tar tools
like GNU tar, which treat the resulting multimember tar.lz archive like
-any other tar.lz archive.
+any other tar.lz archive. Tarlz can append files to the end of such
+compressed archives.
Tarlz can create tar archives with four levels of compression
granularity; per file, per directory, appendable solid, and solid.
- Tarlz is intended as a showcase project for the maintainers of real
-tar programs to evaluate the format and perhaps implement it in their
-tools.
-
- The diagram below shows the correspondence between tar members
-(formed by a header plus optional data) in the tar archive and lzip
-members in the resulting multimember tar.lz archive: *Note File format:
-(lzip)File format.
-
-tar
-+========+======+========+======+========+======+========+
-| header | data | header | data | header | data | eof |
-+========+======+========+======+========+======+========+
-
-tar.lz
-+===============+===============+===============+========+
-| member | member | member | member |
-+===============+===============+===============+========+
-
Of course, compressing each file (or each directory) individually is
less efficient than compressing the whole tar archive, but it has the
following advantages:
@@ -73,21 +54,32 @@ following advantages:
* The resulting multimember tar.lz archive can be decompressed in
parallel with plzip, multiplying the decompression speed.
- * New members can be appended to the archive (by removing the eof
+ * New members can be appended to the archive (by removing the EOF
member) just like to an uncompressed tar archive.
* It is a safe posix-style backup format. In case of corruption,
tarlz can extract all the undamaged members from the tar.lz
archive, skipping over the damaged members, just like the standard
- (uncompressed) tar. Moreover, lziprecover can be used to recover at
- least part of the contents of the damaged members.
+ (uncompressed) tar. Moreover, the option '--keep-damaged' can be
+ used to recover as much data as possible from each damaged member,
+ and lziprecover can be used to recover some of the damaged members.
* A multimember tar.lz archive is usually smaller than the
corresponding solidly compressed tar.gz archive, except when
individually compressing files smaller than about 32 KiB.
+ Tarlz protects the extended records with a CRC in a way compatible
+with standard tar tools. *Note crc32::.
+
+ Tarlz does not understand other tar formats like 'gnu', 'oldgnu',
+'star' or 'v7'.
+
+ Tarlz is intended as a showcase project for the maintainers of real
+tar programs to evaluate the format and perhaps implement it in their
+tools.
+

-File: tarlz.info, Node: Invoking tarlz, Next: Examples, Prev: Introduction, Up: Top
+File: tarlz.info, Node: Invoking tarlz, Next: File format, Prev: Introduction, Up: Top
2 Invoking tarlz
****************
@@ -97,9 +89,15 @@ The format for running tarlz is:
tarlz [OPTIONS] [FILES]
On archive creation or appending, tarlz removes leading and trailing
-slashes from file names, as well as file name prefixes containing a
-'..' component. On extraction, archive members containing a '..'
-component are skipped.
+slashes from filenames, as well as filename prefixes containing a '..'
+component. On extraction, archive members containing a '..' component
+are skipped. Tarlz detects when the archive being created or enlarged
+is among the files to be dumped, appended or concatenated, and skips it.
+
+ On extraction and listing, tarlz removes leading './' strings from
+member names in the archive or given in the command line, so that
+'tarlz -xf foo ./bar baz' extracts members 'bar' and './baz' from
+archive 'foo'.
tarlz supports the following options:
@@ -110,10 +108,22 @@ component are skipped.
'-V'
'--version'
Print the version number of tarlz on the standard output and exit.
+ This version number should be included in all bug reports.
+
+'-A'
+'--concatenate'
+ Append tar.lz archives to the end of a tar.lz archive. All the
+ archives involved must be regular (seekable) files compressed as
+ multimember lzip files, and the two end-of-file blocks plus any
+ zero padding must be contained in the last lzip member of each
+ archive. The intermediate end-of-file blocks are removed as each
+ new archive is concatenated. Exit with status 0 without modifying
+ the archive if no FILES have been specified. Tarlz can't
+ concatenate uncompressed tar archives.
'-c'
'--create'
- Create a new archive.
+ Create a new archive from FILES.
'-C DIR'
'--directory=DIR'
@@ -137,18 +147,19 @@ component are skipped.
'-r'
'--append'
- Append files to the end of an archive. The archive must be a
+ Append files to the end of a tar.lz archive. The archive must be a
regular (seekable) file compressed as a multimember lzip file, and
the two end-of-file blocks plus any zero padding must be contained
in the last lzip member of the archive. First this last member is
removed, then the new members are appended, and then a new
end-of-file member is appended to the archive. Exit with status 0
without modifying the archive if no FILES have been specified.
- tarlz can't append files to an uncompressed tar archive.
+ Tarlz can't append files to an uncompressed tar archive.
'-t'
'--list'
- List the contents of an archive.
+ List the contents of an archive. If FILES are given, list only the
+ given FILES.
'-v'
'--verbose'
@@ -156,10 +167,14 @@ component are skipped.
'-x'
'--extract'
- Extract files from an archive.
+ Extract files from an archive. If FILES are given, extract only
+ the given FILES. Else extract all the files in the archive.
'-0 .. -9'
Set the compression level. The default compression level is '-6'.
+ Like lzip, tarlz also minimizes the dictionary size of the lzip
+ members it creates, reducing the amount of memory required for
+ decompression.
'--asolid'
When creating or appending to a compressed archive, use appendable
@@ -175,23 +190,50 @@ component are skipped.
creates a compressed appendable archive with a separate lzip
member for each top-level directory.
+'--no-solid'
+ When creating or appending to a compressed archive, compress each
+ file separately. The end-of-file blocks are compressed into a
+ separate lzip member. This creates a compressed appendable archive
+ with a separate lzip member for each file. This option allows
+ tarlz revert to default behavior if, for example, tarlz is invoked
+ through an alias like 'tar='tarlz --solid''.
+
'--solid'
When creating or appending to a compressed archive, use solid
compression. The files being added to the archive, along with the
end-of-file blocks, are compressed into a single lzip member. The
resulting archive is not appendable. No more files can be later
- appended to the archive without decompressing it first.
+ appended to the archive.
-'--group=GROUP'
- When creating or appending, use GROUP for files added to the
- archive. If GROUP is not a valid group name, it is decoded as a
- decimal numeric group ID.
+'--anonymous'
+ Equivalent to '--owner=root --group=root'.
'--owner=OWNER'
When creating or appending, use OWNER for files added to the
archive. If OWNER is not a valid user name, it is decoded as a
decimal numeric user ID.
+'--group=GROUP'
+ When creating or appending, use GROUP for files added to the
+ archive. If GROUP is not a valid group name, it is decoded as a
+ decimal numeric group ID.
+
+'--keep-damaged'
+ Don't delete partially extracted files. If a decompression error
+ happens while extracting a file, keep the partial data extracted.
+ Use this option to recover as much data as possible from each
+ damaged member.
+
+'--missing-crc'
+ Exit with error status 2 if the CRC of the extended records is
+ missing. When this option is used, tarlz detects any corruption
+ in the extended records (only limited by CRC collisions). But note
+ that a corrupt 'GNU.crc32' keyword, for example 'GNU.crc33', is
+ reported as a missing CRC instead of as a corrupt record. This
+ misleading 'Missing CRC' message is the consequence of a flaw in
+ the posix pax format; i.e., the lack of a mandatory check sequence
+ in the extended records. *Note crc32::.
+
'--uncompressed'
With '--create', don't compress the created tar archive. Create an
uncompressed tar archive instead.
@@ -203,9 +245,337 @@ invalid input file, 3 for an internal consistency error (eg, bug) which
caused tarlz to panic.

-File: tarlz.info, Node: Examples, Next: Problems, Prev: Invoking tarlz, Up: Top
+File: tarlz.info, Node: File format, Next: Amendments to pax format, Prev: Invoking tarlz, Up: Top
+
+3 File format
+*************
+
+In the diagram below, a box like this:
++---+
+| | <-- the vertical bars might be missing
++---+
+
+ represents one byte; a box like this:
++==============+
+| |
++==============+
+
+ represents a variable number of bytes or a fixed but large number of
+bytes (for example 512).
+
+
+ A tar.lz file consists of a series of lzip members (compressed data
+sets). The members simply appear one after another in the file, with no
+additional information before, between, or after them.
+
+ Each lzip member contains one or more tar members in a simplified
+posix pax interchange format; the only pax typeflag value supported by
+tarlz (in addition to the typeflag values defined by the ustar format)
+is 'x'. The pax format is an extension on top of the ustar format that
+removes the size limitations of the ustar format.
+
+ Each tar member contains one file archived, and is represented by the
+following sequence:
+
+ * An optional extended header block with extended header records.
+ This header block is of the form described in pax header block,
+ with a typeflag value of 'x'. The extended header records are
+ included as the data for this header block.
+
+ * A header block in ustar format that describes the file. Any fields
+ defined in the preceding optional extended header records override
+ the associated fields in this header block for this file.
+
+ * Zero or more blocks that contain the contents of the file.
+
+ At the end of the archive file there are two 512-byte blocks filled
+with binary zeros, interpreted as an end-of-archive indicator. These EOF
+blocks are either compressed in a separate lzip member or compressed
+along with the tar members contained in the last lzip member.
+
+ The diagram below shows the correspondence between each tar member
+(formed by one or two headers plus optional data) in the tar archive and
+each lzip member in the resulting multimember tar.lz archive: *Note
+File format: (lzip)File format.
+
+tar
++========+======+=================+===============+========+======+========+
+| header | data | extended header | extended data | header | data | EOF |
++========+======+=================+===============+========+======+========+
+
+tar.lz
++===============+=================================================+========+
+| member | member | member |
++===============+=================================================+========+
+
+
+3.1 Pax header block
+====================
+
+The pax header block is identical to the ustar header block described
+below except that the typeflag has the value 'x' (extended). The size
+field is the size of the extended header data in bytes. Most other
+fields in the pax header block are zeroed on archive creation to
+prevent trouble if the archive is read by an ustar tool, and are
+ignored by tarlz on archive extraction. *Note flawed-compat::.
+
+ The pax extended header data consists of one or more records, each of
+them constructed as follows:
+'"%d %s=%s\n", <length>, <keyword>, <value>'
+
+ The <length>, <blank>, <keyword>, <equals-sign>, and <newline> in the
+record must be limited to the portable character set. The <length> field
+contains the decimal length of the record in bytes, including the
+trailing <newline>. The <value> field is stored as-is, without
+conversion to UTF-8 nor any other transformation.
+
+ These are the <keyword> fields currently supported by tarlz:
+
+'linkpath'
+ The pathname of a link being created to another file, of any type,
+ previously archived. This record overrides the linkname field in
+ the following ustar header block. The following ustar header block
+ determines the type of link created. If typeflag of the following
+ header block is 1, it will be a hard link. If typeflag is 2, it
+ will be a symbolic link and the linkpath value will be used as the
+ contents of the symbolic link.
+
+'path'
+ The pathname of the following file. This record overrides the name
+ and prefix fields in the following ustar header block.
+
+'size'
+ The size of the file in bytes, expressed as a decimal number using
+ digits from the ISO/IEC 646:1991 (ASCII) standard. This record
+ overrides the size field in the following ustar header block. The
+ size record is used only for files with a size value greater than
+ 8_589_934_591 (octal 77777777777). This is 2^33 bytes or larger.
+
+'GNU.crc32'
+ CRC32-C (Castagnoli) of the extended header data excluding the 8
+ bytes representing the CRC <value> itself. The <value> is
+ represented as 8 hexadecimal digits in big endian order,
+ '22 GNU.crc32=00000000\n'. The keyword of the CRC record is
+ protected by the CRC to guarante that corruption is always detected
+ (except in case of CRC collision). A CRC was chosen because a
+ checksum is too weak for a potentially large list of variable
+ sized records. A checksum can't detect simple errors like the
+ swapping of two bytes.
+
+
+3.2 Ustar header block
+======================
+
+The ustar header block has a length of 512 bytes and is structured as
+shown in the following table. All lengths and offsets are in decimal.
+
+Field Name Offset Length (in bytes)
+name 0 100
+mode 100 8
+uid 108 8
+gid 116 8
+size 124 12
+mtime 136 12
+chksum 148 8
+typeflag 156 1
+linkname 157 100
+magic 257 6
+version 263 2
+uname 265 32
+gname 297 32
+devmajor 329 8
+devminor 337 8
+prefix 345 155
+
+ All characters in the header block are coded using the ISO/IEC
+646:1991 (ASCII) standard, except in fields storing names for files,
+users, and groups. For maximum portability between implementations,
+names should only contain characters from the portable filename
+character set. But if an implementation supports the use of characters
+outside of '/' and the portable filename character set in names for
+files, users, and groups, tarlz will use the byte values in these names
+unmodified.
+
+ The fields name, linkname, and prefix are null-terminated character
+strings except when all characters in the array contain non-null
+characters including the last character.
+
+ The name and the prefix fields produce the pathname of the file. A
+new pathname is formed, if prefix is not an empty string (its first
+character is not null), by concatenating prefix (up to the first null
+character), a <slash> character, and name; otherwise, name is used
+alone. In either case, name is terminated at the first null character.
+If prefix begins with a null character, it is ignored. In this manner,
+pathnames of at most 256 characters can be supported. If a pathname does
+not fit in the space provided, an extended record is used to store the
+pathname.
+
+ The linkname field does not use the prefix to produce a pathname. If
+the linkname does not fit in the 100 characters provided, an extended
+record is used to store the linkname.
+
+ The mode field provides 12 access permission bits. The following
+table shows the symbolic name of each bit and its octal value:
+
+Bit Name Bit value
+S_ISUID 04000
+S_ISGID 02000
+S_ISVTX 01000
+S_IRUSR 00400
+S_IWUSR 00200
+S_IXUSR 00100
+S_IRGRP 00040
+S_IWGRP 00020
+S_IXGRP 00010
+S_IROTH 00004
+S_IWOTH 00002
+S_IXOTH 00001
+
+ The uid and gid fields are the user and group ID of the owner and
+group of the file, respectively.
+
+ The size field contains the octal representation of the size of the
+file in bytes. If the typeflag field specifies a file of type '0'
+(regular file) or '7' (high performance regular file), the number of
+logical records following the header is (size / 512) rounded to the next
+integer. For all other values of typeflag, tarlz either sets the size
+field to 0 or ignores it, and does not store or expect any logical
+records following the header. If the file size is larger than
+8_589_934_591 bytes (octal 77777777777), an extended record is used to
+store the file size.
+
+ The mtime field contains the octal representation of the modification
+time of the file at the time it was archived, obtained from the stat()
+function.
+
+ The chksum field contains the octal representation of the value of
+the simple sum of all bytes in the header logical record. Each byte in
+the header is treated as an unsigned value. When calculating the
+checksum, the chksum field is treated as if it were all <space>
+characters.
+
+ The typeflag field contains a single character specifying the type of
+file archived:
+
+''0''
+ Regular file.
+
+''1''
+ Hard link to another file, of any type, previously archived.
+
+''2''
+ Symbolic link.
+
+''3', '4''
+ Character special file and block special file respectively. In
+ this case the devmajor and devminor fields contain information
+ defining the device in unspecified format.
+
+''5''
+ Directory.
+
+''6''
+ FIFO special file.
+
+''7''
+ Reserved to represent a file to which an implementation has
+ associated some high-performance attribute. Tarlz treats this type
+ of file as a regular file (type 0).
+
+
+ The magic field contains the ASCII null-terminated string "ustar".
+The version field contains the characters "00" (0x30,0x30). The fields
+uname, and gname are null-terminated character strings. Each numeric
+field contains a leading zero-filled, null-terminated octal number using
+digits from the ISO/IEC 646:1991 (ASCII) standard.
+
+
+File: tarlz.info, Node: Amendments to pax format, Next: Examples, Prev: File format, Up: Top
+
+4 The reasons for the differences with pax
+******************************************
+
+Tarlz is meant to reliably detect invalid or corrupt metadata during
+extraction and to not create safety risks in the archives it creates. In
+order to achieve these goals, tarlz makes some changes to the variant
+of the pax format that it uses. This chapter describes these changes
+and the concrete reasons to implement them.
+
+
+4.1 Add a CRC of the extended records
+=====================================
+
+The posix pax format has a serious flaw. The metadata stored in pax
+extended records are not protected by any kind of check sequence.
+Corruption in a long filename may cause the extraction of the file in
+the wrong place without warning. Corruption in a long file size may
+cause the truncation of the file or the appending of garbage to the
+file, both followed by a spurious warning about a corrupt header far
+from the place of the undetected corruption.
+
+ Metadata like filename and file size must be always protected in an
+archive format because of the adverse effects of undetected corruption
+in them, potentially much worse that undetected corruption in the data.
+Even more so in the case of pax because the amount of metadata it
+stores is potentially large, making undetected corruption more probable.
+
+ Because of the above, tarlz protects the extended records with a CRC
+in a way compatible with standard tar tools. *Note key_crc32::.
+
+
+4.2 Remove flawed backward compatibility
+========================================
+
+In order to allow the extraction of pax archives by a tar utility
+conforming to the POSIX-2:1993 standard, POSIX.1-2008 recommends
+selecting extended header field values that allow such tar to create a
+regular file containing the extended header records as data. This
+approach is broken because if the extended header is needed because of
+a long filename, the name and prefix fields will be unable to contain
+the full pathname of the file. Therefore the files corresponding to
+both the extended header and the overridden ustar header will be
+extracted using truncated filenames, perhaps overwriting existing files
+or directories. It may be a security risk to extract a file with a
+truncated filename.
+
+ To avoid this problem, tarlz writes extended headers with all fields
+zeroed except size, chksum, typeflag, magic and version. This prevents
+old tar programs from extracting the extended records as a file in the
+wrong place. Tarlz also sets to zero those fields of the ustar header
+overridden by extended records.
+
+ If the extended header is needed because of a file size larger than
+8 GiB, the size field will be unable to contain the full size of the
+file. Therefore the file may be partially extracted, and the tool will
+issue a spurious warning about a corrupt header at the point where it
+thinks the file ends. Setting to zero the overridden size in the ustar
+header at least prevents the partial extraction and makes obvious that
+the file has been truncated.
+
+
+4.3 As simple as possible (but not simpler)
+===========================================
+
+The tarlz format is mainly ustar. Extended pax headers are used only
+when needed because the length of a filename or link name, or the size
+of a file exceed the limits of the ustar format. Adding extended
+headers to each member just to record subsecond timestamps seems
+wasteful for a backup format.
+
+
+4.4 Avoid misconversions to/from UTF-8
+======================================
+
+There is no portable way to tell what charset a text string is coded
+into. Therefore, tarlz stores all fields representing text strings
+as-is, without conversion to UTF-8 nor any other transformation. This
+prevents accidental double UTF-8 conversions. If the need arises this
+behavior will be adjusted with a command line option in the future.
+
+
+File: tarlz.info, Node: Examples, Next: Problems, Prev: Amendments to pax format, Up: Top
-3 A small tutorial with examples
+5 A small tutorial with examples
********************************
Example 1: Create a multimember compressed archive 'archive.tar.lz'
@@ -232,7 +602,7 @@ Example 4: Create a compressed appendable archive containing directories
'dir1', 'dir2' and 'dir3' with a separate lzip member per directory.
Then append files 'a', 'b', 'c', 'd' and 'e' to the archive, all of
them contained in a single lzip member. The resulting archive
-'archive.tar.lz' contains 5 lzip members (including the eof member).
+'archive.tar.lz' contains 5 lzip members (including the EOF member).
tarlz --dsolid -cf archive.tar.lz dir1 dir2 dir3
tarlz --asolid -rf archive.tar.lz a b c d e
@@ -240,7 +610,7 @@ them contained in a single lzip member. The resulting archive
Example 5: Create a solidly compressed archive 'archive.tar.lz'
containing files 'a', 'b' and 'c'. Note that no more files can be later
-appended to the archive without decompressing it first.
+appended to the archive.
tarlz --solid -cf archive.tar.lz a b c
@@ -263,7 +633,7 @@ Example 8: Copy the contents of directory 'sourcedir' to the directory

File: tarlz.info, Node: Problems, Next: Concept index, Prev: Examples, Up: Top
-4 Reporting bugs
+6 Reporting bugs
****************
There are probably bugs in tarlz. There are certainly errors and
@@ -284,8 +654,11 @@ Concept index
* Menu:
+* Amendments to pax format: Amendments to pax format.
+ (line 6)
* bugs: Problems. (line 6)
* examples: Examples. (line 6)
+* file format: File format. (line 6)
* getting help: Problems. (line 6)
* introduction: Introduction. (line 6)
* invoking: Invoking tarlz. (line 6)
@@ -297,11 +670,16 @@ Concept index

Tag Table:
Node: Top223
-Node: Introduction785
-Node: Invoking tarlz3280
-Node: Examples7278
-Node: Problems8975
-Node: Concept index9501
+Node: Introduction946
+Node: Invoking tarlz3084
+Node: File format9606
+Ref: key_crc3214138
+Node: Amendments to pax format19215
+Ref: crc3219729
+Ref: flawed-compat20753
+Node: Examples23126
+Node: Problems24802
+Node: Concept index25328

End Tag Table
diff --git a/doc/tarlz.texi b/doc/tarlz.texi
index db51dd6..4c6d16a 100644
--- a/doc/tarlz.texi
+++ b/doc/tarlz.texi
@@ -6,8 +6,8 @@
@finalout
@c %**end of header
-@set UPDATED 23 April 2018
-@set VERSION 0.4
+@set UPDATED 16 December 2018
+@set VERSION 0.8
@dircategory Data Compression
@direntry
@@ -35,11 +35,13 @@
This manual is for Tarlz (version @value{VERSION}, @value{UPDATED}).
@menu
-* Introduction:: Purpose and features of tarlz
-* Invoking tarlz:: Command line interface
-* Examples:: A small tutorial with examples
-* Problems:: Reporting bugs
-* Concept index:: Index of concepts
+* Introduction:: Purpose and features of tarlz
+* Invoking tarlz:: Command line interface
+* File format:: Detailed format of the compressed archive
+* Amendments to pax format:: The reasons for the differences with pax
+* Examples:: A small tutorial with examples
+* Problems:: Reporting bugs
+* Concept index:: Index of concepts
@end menu
@sp 1
@@ -53,43 +55,19 @@ to copy, distribute and modify it.
@chapter Introduction
@cindex introduction
-Tarlz is a small and simple implementation of the tar archiver. By
-default tarlz creates, lists and extracts archives in the 'ustar' format
-compressed with lzip on a per file basis. Tarlz can append files to the
-end of such compressed archives.
-
-Each tar member is compressed in its own lzip member, as well as the
-end-of-file blocks. This same method works for any tar format (gnu,
-ustar, posix) and is fully backward compatible with standard tar tools
-like GNU tar, which treat the resulting multimember tar.lz archive like
-any other tar.lz archive.
+@uref{http://www.nongnu.org/lzip/tarlz.html,,Tarlz} is a small and simple
+implementation of the tar archiver. By default tarlz creates, lists and
+extracts archives in a simplified posix pax format compressed with
+@uref{http://www.nongnu.org/lzip/lzip.html,,lzip} on a per file basis. Each
+tar member is compressed in its own lzip member, as well as the end-of-file
+blocks. This method is fully backward compatible with standard tar tools
+like GNU tar, which treat the resulting multimember tar.lz archive like any
+other tar.lz archive. Tarlz can append files to the end of such compressed
+archives.
Tarlz can create tar archives with four levels of compression
granularity; per file, per directory, appendable solid, and solid.
-Tarlz is intended as a showcase project for the maintainers of real tar
-programs to evaluate the format and perhaps implement it in their tools.
-
-The diagram below shows the correspondence between tar members (formed
-by a header plus optional data) in the tar archive and
-@uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#File-format,,lzip members}
-in the resulting multimember tar.lz archive:
-@ifnothtml
-@xref{File format,,,lzip}.
-@end ifnothtml
-
-@verbatim
-tar
-+========+======+========+======+========+======+========+
-| header | data | header | data | header | data | eof |
-+========+======+========+======+========+======+========+
-
-tar.lz
-+===============+===============+===============+========+
-| member | member | member | member |
-+===============+===============+===============+========+
-@end verbatim
-
@noindent
Of course, compressing each file (or each directory) individually is
less efficient than compressing the whole tar archive, but it has the
@@ -101,15 +79,16 @@ The resulting multimember tar.lz archive can be decompressed in
parallel with plzip, multiplying the decompression speed.
@item
-New members can be appended to the archive (by removing the eof
+New members can be appended to the archive (by removing the EOF
member) just like to an uncompressed tar archive.
@item
It is a safe posix-style backup format. In case of corruption,
tarlz can extract all the undamaged members from the tar.lz
archive, skipping over the damaged members, just like the standard
-(uncompressed) tar. Moreover, lziprecover can be used to recover at
-least part of the contents of the damaged members.
+(uncompressed) tar. Moreover, the option @code{--keep-damaged} can be
+used to recover as much data as possible from each damaged member,
+and lziprecover can be used to recover some of the damaged members.
@item
A multimember tar.lz archive is usually smaller than the
@@ -117,6 +96,15 @@ corresponding solidly compressed tar.gz archive, except when
individually compressing files smaller than about 32 KiB.
@end itemize
+Tarlz protects the extended records with a CRC in a way compatible with
+standard tar tools. @xref{crc32}.
+
+Tarlz does not understand other tar formats like @samp{gnu}, @samp{oldgnu},
+@samp{star} or @samp{v7}.
+
+Tarlz is intended as a showcase project for the maintainers of real tar
+programs to evaluate the format and perhaps implement it in their tools.
+
@node Invoking tarlz
@chapter Invoking tarlz
@@ -133,9 +121,16 @@ tarlz [@var{options}] [@var{files}]
@noindent
On archive creation or appending, tarlz removes leading and trailing
-slashes from file names, as well as file name prefixes containing a
+slashes from filenames, as well as filename prefixes containing a
@samp{..} component. On extraction, archive members containing a
-@samp{..} component are skipped.
+@samp{..} component are skipped. Tarlz detects when the archive being
+created or enlarged is among the files to be dumped, appended or
+concatenated, and skips it.
+
+On extraction and listing, tarlz removes leading @samp{./} strings from
+member names in the archive or given in the command line, so that
+@w{@code{tarlz -xf foo ./bar baz}} extracts members @samp{bar} and
+@samp{./baz} from archive @samp{foo}.
tarlz supports the following options:
@@ -147,10 +142,21 @@ Print an informative help message describing the options and exit.
@item -V
@itemx --version
Print the version number of tarlz on the standard output and exit.
+This version number should be included in all bug reports.
+
+@item -A
+@itemx --concatenate
+Append tar.lz archives to the end of a tar.lz archive. All the archives
+involved must be regular (seekable) files compressed as multimember lzip
+files, and the two end-of-file blocks plus any zero padding must be
+contained in the last lzip member of each archive. The intermediate
+end-of-file blocks are removed as each new archive is concatenated. Exit
+with status 0 without modifying the archive if no @var{files} have been
+specified. Tarlz can't concatenate uncompressed tar archives.
@item -c
@itemx --create
-Create a new archive.
+Create a new archive from @var{files}.
@item -C @var{dir}
@itemx --directory=@var{dir}
@@ -174,18 +180,19 @@ Quiet operation. Suppress all messages.
@item -r
@itemx --append
-Append files to the end of an archive. The archive must be a regular
-(seekable) file compressed as a multimember lzip file, and the two
-end-of-file blocks plus any zero padding must be contained in the last
-lzip member of the archive. First this last member is removed, then the
-new members are appended, and then a new end-of-file member is appended
-to the archive. Exit with status 0 without modifying the archive if no
-@var{files} have been specified. tarlz can't append files to an
-uncompressed tar archive.
+Append files to the end of a tar.lz archive. The archive must be a
+regular (seekable) file compressed as a multimember lzip file, and the
+two end-of-file blocks plus any zero padding must be contained in the
+last lzip member of the archive. First this last member is removed, then
+the new members are appended, and then a new end-of-file member is
+appended to the archive. Exit with status 0 without modifying the
+archive if no @var{files} have been specified. Tarlz can't append files
+to an uncompressed tar archive.
@item -t
@itemx --list
-List the contents of an archive.
+List the contents of an archive. If @var{files} are given, list only the
+given @var{files}.
@item -v
@itemx --verbose
@@ -193,10 +200,13 @@ Verbosely list files processed.
@item -x
@itemx --extract
-Extract files from an archive.
+Extract files from an archive. If @var{files} are given, extract only
+the given @var{files}. Else extract all the files in the archive.
@item -0 .. -9
Set the compression level. The default compression level is @samp{-6}.
+Like lzip, tarlz also minimizes the dictionary size of the lzip members
+it creates, reducing the amount of memory required for decompression.
@item --asolid
When creating or appending to a compressed archive, use appendable solid
@@ -212,23 +222,56 @@ end-of-file blocks are compressed into a separate lzip member. This
creates a compressed appendable archive with a separate lzip member for
each top-level directory.
+@item --no-solid
+When creating or appending to a compressed archive, compress each file
+separately. The end-of-file blocks are compressed into a separate lzip
+member. This creates a compressed appendable archive with a separate
+lzip member for each file. This option allows tarlz revert to default
+behavior if, for example, tarlz is invoked through an alias like
+@code{tar='tarlz --solid'}.
+
@item --solid
When creating or appending to a compressed archive, use solid
compression. The files being added to the archive, along with the
end-of-file blocks, are compressed into a single lzip member. The
resulting archive is not appendable. No more files can be later appended
-to the archive without decompressing it first.
+to the archive.
-@item --group=@var{group}
-When creating or appending, use @var{group} for files added to the
-archive. If @var{group} is not a valid group name, it is decoded as a
-decimal numeric group ID.
+@item --anonymous
+Equivalent to @code{--owner=root --group=root}.
@item --owner=@var{owner}
When creating or appending, use @var{owner} for files added to the
archive. If @var{owner} is not a valid user name, it is decoded as a
decimal numeric user ID.
+@item --group=@var{group}
+When creating or appending, use @var{group} for files added to the
+archive. If @var{group} is not a valid group name, it is decoded as a
+decimal numeric group ID.
+
+@item --keep-damaged
+Don't delete partially extracted files. If a decompression error happens
+while extracting a file, keep the partial data extracted. Use this
+option to recover as much data as possible from each damaged member.
+
+@item --missing-crc
+Exit with error status 2 if the CRC of the extended records is missing.
+When this option is used, tarlz detects any corruption in the extended
+records (only limited by CRC collisions). But note that a corrupt
+@samp{GNU.crc32} keyword, for example @samp{GNU.crc33}, is reported as a
+missing CRC instead of as a corrupt record. This misleading
+@samp{Missing CRC} message is the consequence of a flaw in the posix pax
+format; i.e., the lack of a mandatory check sequence in the extended
+records. @xref{crc32}.
+
+@ignore
+@item --permissive
+Allow some violations of the archive format, like consecutive extended
+headers preceding a ustar header, or several records with the same
+keyword appearing in the same block of extended records.
+@end ignore
+
@item --uncompressed
With @code{--create}, don't compress the created tar archive. Create an
uncompressed tar archive instead.
@@ -241,6 +284,358 @@ invalid input file, 3 for an internal consistency error (eg, bug) which
caused tarlz to panic.
+@node File format
+@chapter File format
+@cindex file format
+
+In the diagram below, a box like this:
+@verbatim
++---+
+| | <-- the vertical bars might be missing
++---+
+@end verbatim
+
+represents one byte; a box like this:
+@verbatim
++==============+
+| |
++==============+
+@end verbatim
+
+represents a variable number of bytes or a fixed but large number of
+bytes (for example 512).
+
+@sp 1
+A tar.lz file consists of a series of lzip members (compressed data sets).
+The members simply appear one after another in the file, with no
+additional information before, between, or after them.
+
+Each lzip member contains one or more tar members in a simplified posix
+pax interchange format; the only pax typeflag value supported by tarlz
+(in addition to the typeflag values defined by the ustar format) is
+@samp{x}. The pax format is an extension on top of the ustar format that
+removes the size limitations of the ustar format.
+
+Each tar member contains one file archived, and is represented by the
+following sequence:
+
+@itemize @bullet
+@item
+An optional extended header block with extended header records. This
+header block is of the form described in pax header block, with a
+typeflag value of @samp{x}. The extended header records are included as
+the data for this header block.
+
+@item
+A header block in ustar format that describes the file. Any fields
+defined in the preceding optional extended header records override the
+associated fields in this header block for this file.
+
+@item
+Zero or more blocks that contain the contents of the file.
+@end itemize
+
+At the end of the archive file there are two 512-byte blocks filled with
+binary zeros, interpreted as an end-of-archive indicator. These EOF
+blocks are either compressed in a separate lzip member or compressed
+along with the tar members contained in the last lzip member.
+
+The diagram below shows the correspondence between each tar member
+(formed by one or two headers plus optional data) in the tar archive and
+each
+@uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#File-format,,lzip member}
+in the resulting multimember tar.lz archive:
+@ifnothtml
+@xref{File format,,,lzip}.
+@end ifnothtml
+
+@verbatim
+tar
++========+======+=================+===============+========+======+========+
+| header | data | extended header | extended data | header | data | EOF |
++========+======+=================+===============+========+======+========+
+
+tar.lz
++===============+=================================================+========+
+| member | member | member |
++===============+=================================================+========+
+@end verbatim
+
+@ignore
+When @code{--permissive} is used, the following violations of the
+archive format are allowed:@*
+If several extended headers precede an ustar header, only the last
+extended header takes effect. The other extended headers are ignored.
+Similarly, if several records with the same keyword appear in the same
+block of extended records, only the last record for the repeated keyword
+takes effect. The other records for the repeated keyword are ignored.
+@end ignore
+
+@sp 1
+@section Pax header block
+
+The pax header block is identical to the ustar header block described below
+except that the typeflag has the value @samp{x} (extended). The size field
+is the size of the extended header data in bytes. Most other fields in the
+pax header block are zeroed on archive creation to prevent trouble if the
+archive is read by an ustar tool, and are ignored by tarlz on archive
+extraction. @xref{flawed-compat}.
+
+The pax extended header data consists of one or more records, each of
+them constructed as follows:@*
+@code{"%d %s=%s\n", <length>, <keyword>, <value>}
+
+The <length>, <blank>, <keyword>, <equals-sign>, and <newline> in the
+record must be limited to the portable character set. The <length> field
+contains the decimal length of the record in bytes, including the
+trailing <newline>. The <value> field is stored as-is, without
+conversion to UTF-8 nor any other transformation.
+
+These are the <keyword> fields currently supported by tarlz:
+
+@table @code
+@item linkpath
+The pathname of a link being created to another file, of any type,
+previously archived. This record overrides the linkname field in the
+following ustar header block. The following ustar header block
+determines the type of link created. If typeflag of the following header
+block is 1, it will be a hard link. If typeflag is 2, it will be a
+symbolic link and the linkpath value will be used as the contents of the
+symbolic link.
+
+@item path
+The pathname of the following file. This record overrides the name and
+prefix fields in the following ustar header block.
+
+@item size
+The size of the file in bytes, expressed as a decimal number using
+digits from the ISO/IEC 646:1991 (ASCII) standard. This record overrides
+the size field in the following ustar header block. The size record is
+used only for files with a size value greater than 8_589_934_591
+@w{(octal 77777777777)}. This is 2^33 bytes or larger.
+
+@anchor{key_crc32}
+@item GNU.crc32
+CRC32-C (Castagnoli) of the extended header data excluding the 8 bytes
+representing the CRC <value> itself. The <value> is represented as 8
+hexadecimal digits in big endian order,
+@w{@samp{22 GNU.crc32=00000000\n}}. The keyword of the CRC record is
+protected by the CRC to guarante that corruption is always detected
+(except in case of CRC collision). A CRC was chosen because a checksum
+is too weak for a potentially large list of variable sized records. A
+checksum can't detect simple errors like the swapping of two bytes.
+@end table
+
+@sp 1
+@section Ustar header block
+
+The ustar header block has a length of 512 bytes and is structured as
+shown in the following table. All lengths and offsets are in decimal.
+
+@multitable {Field Name} {Offset} {Length (in bytes)}
+@item Field Name @tab Offset @tab Length (in bytes)
+@item name @tab 0 @tab 100
+@item mode @tab 100 @tab 8
+@item uid @tab 108 @tab 8
+@item gid @tab 116 @tab 8
+@item size @tab 124 @tab 12
+@item mtime @tab 136 @tab 12
+@item chksum @tab 148 @tab 8
+@item typeflag @tab 156 @tab 1
+@item linkname @tab 157 @tab 100
+@item magic @tab 257 @tab 6
+@item version @tab 263 @tab 2
+@item uname @tab 265 @tab 32
+@item gname @tab 297 @tab 32
+@item devmajor @tab 329 @tab 8
+@item devminor @tab 337 @tab 8
+@item prefix @tab 345 @tab 155
+@end multitable
+
+All characters in the header block are coded using the ISO/IEC 646:1991
+(ASCII) standard, except in fields storing names for files, users, and
+groups. For maximum portability between implementations, names should
+only contain characters from the portable filename character set. But if
+an implementation supports the use of characters outside of @samp{/} and
+the portable filename character set in names for files, users, and
+groups, tarlz will use the byte values in these names unmodified.
+
+The fields name, linkname, and prefix are null-terminated character
+strings except when all characters in the array contain non-null
+characters including the last character.
+
+The name and the prefix fields produce the pathname of the file. A new
+pathname is formed, if prefix is not an empty string (its first
+character is not null), by concatenating prefix (up to the first null
+character), a <slash> character, and name; otherwise, name is used
+alone. In either case, name is terminated at the first null character.
+If prefix begins with a null character, it is ignored. In this manner,
+pathnames of at most 256 characters can be supported. If a pathname does
+not fit in the space provided, an extended record is used to store the
+pathname.
+
+The linkname field does not use the prefix to produce a pathname. If the
+linkname does not fit in the 100 characters provided, an extended record
+is used to store the linkname.
+
+The mode field provides 12 access permission bits. The following table
+shows the symbolic name of each bit and its octal value:
+
+@multitable {Bit Name} {Bit value}
+@item Bit Name @tab Bit value
+@item S_ISUID @tab 04000
+@item S_ISGID @tab 02000
+@item S_ISVTX @tab 01000
+@item S_IRUSR @tab 00400
+@item S_IWUSR @tab 00200
+@item S_IXUSR @tab 00100
+@item S_IRGRP @tab 00040
+@item S_IWGRP @tab 00020
+@item S_IXGRP @tab 00010
+@item S_IROTH @tab 00004
+@item S_IWOTH @tab 00002
+@item S_IXOTH @tab 00001
+@end multitable
+
+The uid and gid fields are the user and group ID of the owner and group
+of the file, respectively.
+
+The size field contains the octal representation of the size of the file
+in bytes. If the typeflag field specifies a file of type '0' (regular
+file) or '7' (high performance regular file), the number of logical
+records following the header is @w{(size / 512)} rounded to the next
+integer. For all other values of typeflag, tarlz either sets the size
+field to 0 or ignores it, and does not store or expect any logical
+records following the header. If the file size is larger than
+8_589_934_591 bytes @w{(octal 77777777777)}, an extended record is used
+to store the file size.
+
+The mtime field contains the octal representation of the modification
+time of the file at the time it was archived, obtained from the stat()
+function.
+
+The chksum field contains the octal representation of the value of the
+simple sum of all bytes in the header logical record. Each byte in the
+header is treated as an unsigned value. When calculating the checksum,
+the chksum field is treated as if it were all <space> characters.
+
+The typeflag field contains a single character specifying the type of
+file archived:
+
+@table @code
+@item '0'
+Regular file.
+
+@item '1'
+Hard link to another file, of any type, previously archived.
+
+@item '2'
+Symbolic link.
+
+@item '3', '4'
+Character special file and block special file respectively. In this case
+the devmajor and devminor fields contain information defining the
+device in unspecified format.
+
+@item '5'
+Directory.
+
+@item '6'
+FIFO special file.
+
+@item '7'
+Reserved to represent a file to which an implementation has associated
+some high-performance attribute. Tarlz treats this type of file as a
+regular file (type 0).
+
+@end table
+
+The magic field contains the ASCII null-terminated string "ustar". The
+version field contains the characters "00" (0x30,0x30). The fields
+uname, and gname are null-terminated character strings. Each numeric
+field contains a leading zero-filled, null-terminated octal number using
+digits from the ISO/IEC 646:1991 (ASCII) standard.
+
+
+@node Amendments to pax format
+@chapter The reasons for the differences with pax
+@cindex Amendments to pax format
+
+Tarlz is meant to reliably detect invalid or corrupt metadata during
+extraction and to not create safety risks in the archives it creates. In
+order to achieve these goals, tarlz makes some changes to the variant of the
+pax format that it uses. This chapter describes these changes and the
+concrete reasons to implement them.
+
+@sp 1
+@anchor{crc32}
+@section Add a CRC of the extended records
+
+The posix pax format has a serious flaw. The metadata stored in pax extended
+records are not protected by any kind of check sequence. Corruption in a
+long filename may cause the extraction of the file in the wrong place
+without warning. Corruption in a long file size may cause the truncation of
+the file or the appending of garbage to the file, both followed by a
+spurious warning about a corrupt header far from the place of the undetected
+corruption.
+
+Metadata like filename and file size must be always protected in an archive
+format because of the adverse effects of undetected corruption in them,
+potentially much worse that undetected corruption in the data. Even more so
+in the case of pax because the amount of metadata it stores is potentially
+large, making undetected corruption more probable.
+
+Because of the above, tarlz protects the extended records with a CRC in
+a way compatible with standard tar tools. @xref{key_crc32}.
+
+@sp 1
+@anchor{flawed-compat}
+@section Remove flawed backward compatibility
+
+In order to allow the extraction of pax archives by a tar utility conforming
+to the POSIX-2:1993 standard, POSIX.1-2008 recommends selecting extended
+header field values that allow such tar to create a regular file containing
+the extended header records as data. This approach is broken because if the
+extended header is needed because of a long filename, the name and prefix
+fields will be unable to contain the full pathname of the file. Therefore
+the files corresponding to both the extended header and the overridden ustar
+header will be extracted using truncated filenames, perhaps overwriting
+existing files or directories. It may be a security risk to extract a file
+with a truncated filename.
+
+To avoid this problem, tarlz writes extended headers with all fields zeroed
+except size, chksum, typeflag, magic and version. This prevents old tar
+programs from extracting the extended records as a file in the wrong place.
+Tarlz also sets to zero those fields of the ustar header overridden by
+extended records.
+
+If the extended header is needed because of a file size larger than
+@w{8 GiB}, the size field will be unable to contain the full size of the
+file. Therefore the file may be partially extracted, and the tool will issue
+a spurious warning about a corrupt header at the point where it thinks the
+file ends. Setting to zero the overridden size in the ustar header at least
+prevents the partial extraction and makes obvious that the file has been
+truncated.
+
+@sp 1
+@section As simple as possible (but not simpler)
+
+The tarlz format is mainly ustar. Extended pax headers are used only when
+needed because the length of a filename or link name, or the size of a file
+exceed the limits of the ustar format. Adding extended headers to each
+member just to record subsecond timestamps seems wasteful for a backup
+format.
+
+@sp 1
+@section Avoid misconversions to/from UTF-8
+
+There is no portable way to tell what charset a text string is coded into.
+Therefore, tarlz stores all fields representing text strings as-is, without
+conversion to UTF-8 nor any other transformation. This prevents accidental
+double UTF-8 conversions. If the need arises this behavior will be adjusted
+with a command line option in the future.
+
+
@node Examples
@chapter A small tutorial with examples
@cindex examples
@@ -280,7 +675,7 @@ Example 4: Create a compressed appendable archive containing directories
directory. Then append files @samp{a}, @samp{b}, @samp{c}, @samp{d} and
@samp{e} to the archive, all of them contained in a single lzip member.
The resulting archive @samp{archive.tar.lz} contains 5 lzip members
-(including the eof member).
+(including the EOF member).
@example
tarlz --dsolid -cf archive.tar.lz dir1 dir2 dir3
@@ -291,8 +686,7 @@ tarlz --asolid -rf archive.tar.lz a b c d e
@noindent
Example 5: Create a solidly compressed archive @samp{archive.tar.lz}
containing files @samp{a}, @samp{b} and @samp{c}. Note that no more
-files can be later appended to the archive without decompressing it
-first.
+files can be later appended to the archive.
@example
tarlz --solid -cf archive.tar.lz a b c
diff --git a/extract.cc b/extract.cc
index 67f4a20..58cda61 100644
--- a/extract.cc
+++ b/extract.cc
@@ -28,6 +28,10 @@
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#if defined(__GNU_LIBRARY__)
+#include <sys/sysmacros.h> // for makedev
+#endif
#include <lzlib.h>
#include "arg_parser.h"
@@ -38,6 +42,17 @@
namespace {
int gretval = 0;
+bool has_lz_ext; // global var for archive_read
+
+void skip_warn( const bool reset = false ) // avoid duplicate warnings
+ {
+ static bool skipping = false;
+
+ if( reset ) skipping = false;
+ else if( !skipping )
+ { skipping = true; show_error( "Skipping to next header." ); }
+ }
+
bool make_path( const std::string & name )
{
@@ -68,42 +83,6 @@ bool make_path( const std::string & name )
}
-// Returns in buf the first rd bytes of the second lzip member or
-// the first 512 bytes of the second tar member, and sets islz if lzip member
-bool skip_first_member( const int infd, uint8_t * const buf,
- int & rd, bool & islz )
- {
- while( true )
- {
- for( int i = 0; i < rd; ++i )
- if( buf[i] == 'L' && (*(Lzip_header *)( buf + i )).verify_prefix( rd - i ) )
- {
- const int ts = rd - i; // tail size
- std::memmove( buf, buf + i, ts );
- if( ts >= (int)sizeof lzip_magic )
- { rd = ts; islz = true; return true; }
- int rd2 = readblock( infd, buf + ts, header_size - ts );
- if( rd2 != header_size - ts && errno )
- { show_error( "Error reading archive", errno ); return false; }
- if( ts + rd2 >= min_member_size &&
- (*(Lzip_header *)buf).verify_magic() )
- { rd = ts + rd2; islz = true; return true; }
- std::memmove( buf, buf + ts, rd2 );
- int rd3 = readblock( infd, buf + rd2, header_size - rd2 );
- if( rd3 != header_size - rd2 && errno )
- { show_error( "Error reading archive", errno ); return false; }
- rd = rd2 + rd3; i = -1;
- }
- if( rd < header_size ) return false; // eof
- if( rd == header_size && verify_ustar_chksum( buf ) )
- { islz = false; return true; }
- rd = readblock( infd, buf, header_size );
- if( rd != header_size && errno )
- { show_error( "Error reading archive", errno ); return false; }
- }
- }
-
-
inline bool block_is_zero( const uint8_t * const buf, const int size )
{
for( int i = 0; i < size; ++i ) if( buf[i] != 0 ) return false;
@@ -111,58 +90,83 @@ inline bool block_is_zero( const uint8_t * const buf, const int size )
}
-bool archive_read( const int infd, uint8_t * const buf, const int size )
+// Return value: 0 = OK, 1 = damaged member, 2 = fatal error.
+// If sizep and error, return in *sizep the number of bytes read.
+// The first 6 bytes of the archive must be intact for islz to be meaningful.
+int archive_read( const int infd, uint8_t * const buf, const int size,
+ int * const sizep = 0 )
{
static LZ_Decoder * decoder = 0;
- static bool first_call = true;
static bool at_eof = false;
+ static bool fatal = false;
+ static bool first_call = true;
+ if( sizep ) *sizep = 0;
+ if( fatal ) return 2;
if( first_call ) // check format
{
first_call = false;
if( size != header_size )
internal_error( "size != header_size on first call." );
- int rd = readblock( infd, buf, size );
+ const int rd = readblock( infd, buf, size );
+ if( sizep ) *sizep = rd;
if( rd != size && errno )
- { show_error( "Error reading archive", errno ); return false; }
- bool islz =
- ( rd >= min_member_size && (*(Lzip_header *)buf).verify_magic() );
+ { show_error( "Error reading archive", errno ); fatal = true; return 2; }
+ const Lzip_header & header = (*(const Lzip_header *)buf);
+ bool islz = ( rd >= min_member_size && header.verify_magic() &&
+ isvalid_ds( header.dictionary_size() ) );
const bool istar = ( rd == size && verify_ustar_chksum( buf ) );
const bool iseof =
( !islz && !istar && rd == size && block_is_zero( buf, size ) );
- if( !islz && !istar && !iseof )
+ if( !islz && !istar && !iseof ) // corrupt or invalid format
{
- show_error( "This does not look like a tar archive." );
- show_error( "Skipping to next header." );
-// std::fprintf( stderr, "%07o\n", ustar_chksum( buf ) );
- gretval = 2;
- if( !skip_first_member( infd, buf, rd, islz ) ) return false;
+ show_error( "This does not look like a POSIX tar archive." );
+ if( has_lz_ext ) islz = true;
+ if( verbosity >= 2 && !islz && rd == size )
+ std::fprintf( stderr, "ustar chksum = %07o\n", ustar_chksum( buf ) );
+ if( !islz ) return 1;
}
- if( !islz ) return true; // uncompressed
+ if( !islz ) // uncompressed
+ { if( rd == size ) return 0; fatal = true; return 2; }
decoder = LZ_decompress_open(); // compressed
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
{ show_error( "Not enough memory." );
- LZ_decompress_close( decoder ); return false; }
+ LZ_decompress_close( decoder ); fatal = true; return 2; }
if( LZ_decompress_write( decoder, buf, rd ) != rd )
internal_error( "library error (LZ_decompress_write)." );
- if( !archive_read( infd, buf, size ) ) return false;
- if( verify_ustar_chksum( buf ) || block_is_zero( buf, size ) ) return true;
- show_error( "This does not look like a tar archive." );
- show_error( "Skipping to next header." );
- gretval = 2;
- if( LZ_decompress_sync_to_member( decoder ) < 0 )
- internal_error( "library error (LZ_decompress_sync_to_member)." );
+ const int res = archive_read( infd, buf, size, sizep );
+ if( res != 0 ) { if( res == 2 ) fatal = true; return res; }
+ if( verify_ustar_chksum( buf ) || block_is_zero( buf, size ) ) return 0;
+ show_error( "This does not look like a POSIX tar.lz archive." );
+ fatal = true; return 2;
}
if( !decoder ) // uncompressed
- { if( readblock( infd, buf, size ) == size ) return true;
- show_error( "Archive ends unexpectedly." ); return false; }
+ {
+ const int rd = readblock( infd, buf, size ); if( rd == size ) return 0;
+ if( sizep ) *sizep = rd;
+ show_error( "Archive ends unexpectedly." ); fatal = true; return 2;
+ }
const int ibuf_size = 16384;
uint8_t ibuf[ibuf_size];
int sz = 0;
while( sz < size )
{
- if( !at_eof && LZ_decompress_write_size( decoder ) > 0 )
+ const int rd = LZ_decompress_read( decoder, buf + sz, size - sz );
+ if( rd < 0 )
+ {
+ if( LZ_decompress_sync_to_member( decoder ) < 0 )
+ internal_error( "library error (LZ_decompress_sync_to_member)." );
+ skip_warn(); gretval = 2; return 1;
+ }
+ if( rd == 0 && LZ_decompress_finished( decoder ) == 1 )
+ { LZ_decompress_close( decoder );
+ show_error( "Archive ends unexpectedly." ); fatal = true; return 2; }
+ sz += rd; if( sizep ) *sizep = sz;
+ if( sz == size && LZ_decompress_finished( decoder ) == 1 &&
+ LZ_decompress_close( decoder ) < 0 )
+ { show_error( "LZ_decompress_close failed." ); fatal = true; return 2; }
+ if( sz < size && !at_eof && LZ_decompress_write_size( decoder ) > 0 )
{
const int rsize = std::min( ibuf_size, LZ_decompress_write_size( decoder ) );
const int rd = readblock( infd, ibuf, rsize );
@@ -172,27 +176,12 @@ bool archive_read( const int infd, uint8_t * const buf, const int size )
{
at_eof = true; LZ_decompress_finish( decoder );
if( errno )
- { show_error( "Error reading archive", errno ); return false; }
+ { show_error( "Error reading archive", errno ); fatal = true;
+ return 2; }
}
}
- const int rd = LZ_decompress_read( decoder, buf + sz, size - sz );
- if( rd < 0 )
- {
- show_error( "Skipping to next header." );
- gretval = 2;
- if( LZ_decompress_sync_to_member( decoder ) < 0 )
- internal_error( "library error (LZ_decompress_sync_to_member)." );
- continue;
- }
- if( rd == 0 && LZ_decompress_finished( decoder ) == 1 )
- { LZ_decompress_close( decoder );
- show_error( "Archive ends unexpectedly." ); return false; }
- sz += rd;
- if( sz == size && LZ_decompress_finished( decoder ) == 1 &&
- LZ_decompress_close( decoder ) < 0 )
- { show_error( "LZ_decompress_close failed." ); return false; }
}
- return true;
+ return 0;
}
@@ -251,55 +240,44 @@ const char * user_group_string( const Tar_header header )
}
-const char * link_string( const Tar_header header )
- {
- enum { bufsize = 9 + linkname_l + 1 };
- static char buf[bufsize];
- const Typeflag typeflag = (Typeflag)header[typeflag_o];
-
- if( typeflag == tf_link )
- snprintf( buf, bufsize, " link to %.100s", header + linkname_o );
- else if( typeflag == tf_symlink )
- snprintf( buf, bufsize, " -> %.100s", header + linkname_o );
- else buf[0] = 0;
- return buf;
- }
-
-
-void show_member_name( const char * const filename, const Tar_header header,
+void show_member_name( const Extended & extended, const Tar_header header,
const int vlevel )
{
if( verbosity < vlevel ) return;
if( verbosity > vlevel )
{
const time_t mtime = strtoull( header + mtime_o, 0, 8 ); // 33 bits
- struct tm * tm = localtime( &mtime );
- std::printf( "%s %s %9llu %4d-%02u-%02u %02u:%02u %s%s\n",
+ const struct tm * const tm = localtime( &mtime );
+ const Typeflag typeflag = (Typeflag)header[typeflag_o];
+ const bool islink = ( typeflag == tf_link || typeflag == tf_symlink );
+ const char * const link_string = !islink ? "" :
+ ( ( typeflag == tf_link ) ? " link to " : " -> " );
+ std::printf( "%s %s %9llu %4d-%02u-%02u %02u:%02u %s%s%s\n",
mode_string( header ), user_group_string( header ),
- strtoull( header + size_o, 0, 8 ), 1900 + tm->tm_year,
- 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min,
- filename, link_string( header ) );
+ extended.size, 1900 + tm->tm_year, 1 + tm->tm_mon,
+ tm->tm_mday, tm->tm_hour, tm->tm_min, extended.path.c_str(),
+ link_string, !islink ? "" : extended.linkpath.c_str() );
}
- else std::printf( "%s\n", filename );
+ else std::printf( "%s\n", extended.path.c_str() );
std::fflush( stdout );
}
-int list_member( const int infd, const char * const filename,
- const unsigned long long file_size, const Tar_header header,
- const bool skip )
+int list_member( const int infd, const Extended & extended,
+ const Tar_header header, const bool skip )
{
- if( !skip ) show_member_name( filename, header, 0 );
+ if( !skip ) show_member_name( extended, header, 0 );
const unsigned bufsize = 32 * header_size;
uint8_t buf[bufsize];
- unsigned long long rest = file_size;
- const int rem = file_size % header_size;
+ unsigned long long rest = extended.size;
+ const int rem = extended.size % header_size;
const int padding = rem ? header_size - rem : 0;
while( rest > 0 )
{
const int rsize = ( rest >= bufsize ) ? bufsize : rest + padding;
- if( !archive_read( infd, buf, rsize ) ) return 2;
+ const int ret = archive_read( infd, buf, rsize );
+ if( ret != 0 ) { if( ret == 2 ) return 2; else break; }
if( rest < bufsize ) break;
rest -= rsize;
}
@@ -317,13 +295,14 @@ bool contains_dotdot( const char * const filename )
}
-int extract_member( const int infd, const char * const filename,
- const unsigned long long file_size, const Tar_header header )
+int extract_member( const int infd, const Extended & extended,
+ const Tar_header header, const bool keep_damaged )
{
+ const char * const filename = extended.path.c_str();
if( contains_dotdot( filename ) )
{
show_file_error( filename, "Contains a '..' component, skipping." );
- return list_member( infd, filename, file_size, header, true );
+ return list_member( infd, extended, header, true );
}
const mode_t mode = strtoul( header + mode_o, 0, 8 ); // 12 bits
const time_t mtime = strtoull( header + mtime_o, 0, 8 ); // 33 bits
@@ -331,7 +310,7 @@ int extract_member( const int infd, const char * const filename,
const bool islink = ( typeflag == tf_link || typeflag == tf_symlink );
int outfd = -1;
- show_member_name( filename, header, 1 );
+ show_member_name( extended, header, 1 );
std::remove( filename );
make_path( filename );
switch( typeflag )
@@ -345,14 +324,12 @@ int extract_member( const int infd, const char * const filename,
case tf_link:
case tf_symlink:
{
- char linkname[linkname_l+1];
- std::memcpy( linkname, header + linkname_o, linkname_l );
- linkname[linkname_l] = 0;
+ const char * const linkname = extended.linkpath.c_str();
/* if( contains_dotdot( linkname ) )
{
show_file_error( filename,
"Link destination contains a '..' component, skipping." );
- return list_member( infd, filename, file_size, header, false );
+ return list_member( infd, extended, header, false );
}*/
const bool hard = typeflag == tf_link;
if( ( hard && link( linkname, filename ) != 0 ) ||
@@ -410,15 +387,25 @@ int extract_member( const int infd, const char * const filename,
const unsigned bufsize = 32 * header_size;
uint8_t buf[bufsize];
- unsigned long long rest = file_size;
- const int rem = file_size % header_size;
+ unsigned long long rest = extended.size;
+ const int rem = extended.size % header_size;
const int padding = rem ? header_size - rem : 0;
while( rest > 0 )
{
const int rsize = ( rest >= bufsize ) ? bufsize : rest + padding;
- if( !archive_read( infd, buf, rsize ) )
- { if( outfd >= 0 ) { close( outfd ); std::remove( filename ); }
- return 2; }
+ int rd;
+ const int ret = archive_read( infd, buf, rsize, &rd );
+ if( ret != 0 )
+ {
+ if( outfd >= 0 )
+ {
+ if( keep_damaged )
+ { writeblock( outfd, buf, std::min( rest, (unsigned long long)rd ) );
+ close( outfd ); }
+ else { close( outfd ); std::remove( filename ); }
+ }
+ if( ret == 2 ) return 2; else return 0;
+ }
const int wsize = ( rest >= bufsize ) ? bufsize : rest;
if( outfd >= 0 && writeblock( outfd, buf, wsize ) != wsize )
{ show_file_error( filename, "Error writing file", errno ); return 2; }
@@ -437,6 +424,7 @@ int extract_member( const int infd, const char * const filename,
}
+// Removes any amount of leading "./" and '/' strings.
const char * remove_leading_slash( const char * const filename )
{
static bool first_post = true;
@@ -479,73 +467,173 @@ bool compare_tslash( const char * const name1, const char * const name2 )
} // end namespace
+bool Extended::parse( const int infd, const Tar_header header,
+ const bool permissive )
+ {
+ const unsigned long long edsize = strtoull( header + size_o, 0, 8 );
+ const unsigned long long bufsize = round_up( edsize );
+ if( bufsize == 0 || edsize == 0 || edsize >= 1ULL << 33 )
+ return false; // overflow or no extended data
+ char * const buf = new char[bufsize]; // extended records buffer
+ if( archive_read( infd, (uint8_t *)buf, bufsize ) != 0 ) goto error;
+ for( unsigned long long pos = 0; pos < edsize; ) // parse records
+ {
+ char * tail;
+ const unsigned long long rsize = strtoull( buf + pos, &tail, 10 );
+ if( rsize == 0 || rsize > edsize - pos || tail[0] != ' ' ||
+ buf[pos+rsize-1] != '\n' ) goto error;
+ ++tail; // point to keyword
+ // length of (keyword + '=' + value) without the final newline
+ const unsigned long long rest = ( buf + pos + rsize - 1 ) - tail;
+ if( rest > 5 && std::memcmp( tail, "path=", 5 ) == 0 )
+ { if( path.size() && !permissive ) goto error;
+ path.assign( tail + 5, rest - 5 ); }
+ else if( rest > 9 && std::memcmp( tail, "linkpath=", 9 ) == 0 )
+ { if( linkpath.size() && !permissive ) goto error;
+ linkpath.assign( tail + 9, rest - 9 ); }
+ else if( rest > 5 && std::memcmp( tail, "size=", 5 ) == 0 )
+ {
+ if( size != 0 && !permissive ) goto error;
+ size = 0;
+ for( unsigned long long i = 5; i < rest; ++i )
+ {
+ if( tail[i] < '0' || tail[i] > '9' ) goto error;
+ const unsigned long long prev = size;
+ size = size * 10 + ( tail[i] - '0' );
+ if( size < prev ) goto error; // overflow
+ }
+ if( size < 1ULL << 33 ) goto error; // size fits in ustar header
+ }
+ else if( rest > 10 && std::memcmp( tail, "GNU.crc32=", 10 ) == 0 )
+ {
+ if( crc_present && !permissive ) goto error;
+ if( rsize != 22 ) goto error;
+ char * t;
+ const uint32_t stored_crc = strtoul( tail + 10, &t, 16 );
+ if( t - tail - 10 != 8 || t[0] != '\n' ) goto error;
+ const uint32_t computed_crc =
+ crc32c.windowed_crc( (const uint8_t *)buf, pos + rsize - 9, edsize );
+ crc_present = true;
+ if( stored_crc != computed_crc ) goto error;
+ }
+ pos += rsize;
+ }
+ delete[] buf;
+ return true;
+error:
+ delete[] buf;
+ return false;
+ }
+
+
int decode( const std::string & archive_name, const Arg_parser & parser,
- const int filenames, const bool listing )
+ const int filenames, const bool keep_damaged, const bool listing,
+ const bool missing_crc, const bool permissive )
{
const int infd = archive_name.size() ?
open_instream( archive_name ) : STDIN_FILENO;
if( infd < 0 ) return 1;
+ // execute -C options and mark filenames to be extracted or listed
std::vector< bool > name_pending( parser.arguments(), false );
for( int i = 0; i < parser.arguments(); ++i )
{
const int code = parser.code( i );
if( code == 'C' && !listing )
{
- const char * const filename = parser.argument( i ).c_str();
- if( chdir( filename ) != 0 )
- { show_file_error( filename, "Error changing working directory", errno );
+ const char * const dir = parser.argument( i ).c_str();
+ if( chdir( dir ) != 0 )
+ { show_file_error( dir, "Error changing working directory", errno );
return 1; }
}
if( !code ) name_pending[i] = true;
}
+ has_lz_ext =
+ ( archive_name.size() > 3 &&
+ archive_name.compare( archive_name.size() - 3, 3, ".lz" ) == 0 ) ||
+ ( archive_name.size() > 4 &&
+ archive_name.compare( archive_name.size() - 4, 4, ".tlz" ) == 0 );
+ Extended extended; // metadata from extended records
int retval = 0;
- bool skipping = false;
+ bool prev_extended = false; // prev header was extended
while( true ) // process one member per iteration
{
uint8_t buf[header_size];
- if( !archive_read( infd, buf, header_size ) ) return 2;
- if( !verify_ustar_chksum( buf ) )
+ const int ret = archive_read( infd, buf, header_size );
+ if( ret == 2 ) return 2;
+ if( ret != 0 || !verify_ustar_chksum( buf ) )
{
- if( block_is_zero( buf, header_size ) ) break;
- gretval = 2;
- if( !skipping )
- { skipping = true; show_error( "Skipping to next header." ); }
- continue;
+ if( ret == 0 && block_is_zero( buf, header_size ) ) break; // EOF
+ skip_warn(); gretval = 2; continue;
}
- skipping = false;
+ skip_warn( true ); // reset warning
const char * const header = (const char *)buf;
- enum { max_filename_size = prefix_l + 1 + name_l + 1 };
- char stored_name[max_filename_size];
- int len = 0;
- while( len < prefix_l && header[prefix_o+len] )
- { stored_name[len] = header[prefix_o+len]; ++len; }
- if( len && header[name_o] ) stored_name[len++] = '/';
- for( int i = 0; i < name_l && header[name_o+i]; ++i )
- { stored_name[len] = header[name_o+i]; ++len; }
- while( len > 0 && stored_name[len-1] == '/' ) --len; // trailing '/'
- stored_name[len] = 0;
- const char * const filename = remove_leading_slash( stored_name );
+ const Typeflag typeflag = (Typeflag)header[typeflag_o];
+ if( typeflag == tf_extended )
+ {
+ if( prev_extended && !permissive )
+ { show_error( "Format violation: consecutive extended headers found."
+ /*" Use --permissive."*/, 0, true ); return 2; }
+ if( !extended.parse( infd, header, permissive ) )
+ { show_error( "Error in extended records. Skipping to next header." );
+ extended.reset(); gretval = 2; }
+ else if( !extended.crc_present && missing_crc )
+ { show_error( "Missing CRC in extended records.", 0, true ); return 2; }
+ prev_extended = true;
+ continue;
+ }
+ prev_extended = false;
+
+ if( extended.linkpath.empty() )
+ {
+ for( int i = 0; i < linkname_l && header[linkname_o+i]; ++i )
+ extended.linkpath += header[linkname_o+i];
+ while( extended.linkpath.size() > 1 && // trailing '/'
+ extended.linkpath[extended.linkpath.size()-1] == '/' )
+ extended.linkpath.resize( extended.linkpath.size() - 1 );
+ }
+
+ if( extended.path.empty() )
+ {
+ char stored_name[prefix_l+1+name_l+1];
+ int len = 0;
+ while( len < prefix_l && header[prefix_o+len] )
+ { stored_name[len] = header[prefix_o+len]; ++len; }
+ if( len && header[name_o] ) stored_name[len++] = '/';
+ for( int i = 0; i < name_l && header[name_o+i]; ++i )
+ { stored_name[len] = header[name_o+i]; ++len; }
+ while( len > 0 && stored_name[len-1] == '/' ) --len; // trailing '/'
+ stored_name[len] = 0;
+ extended.path = remove_leading_slash( stored_name );
+ }
+ const char * const filename = extended.path.c_str();
bool skip = filenames > 0;
if( skip )
for( int i = 0; i < parser.arguments(); ++i )
- if( parser.code( i ) == 0 &&
- ( compare_prefix_dir( parser.argument( i ).c_str(), filename ) ||
- compare_tslash( filename, parser.argument( i ).c_str() ) ) )
- { skip = false; name_pending[i] = false; break; }
+ if( parser.code( i ) == 0 )
+ {
+ const char * const name =
+ remove_leading_slash( parser.argument( i ).c_str() );
+ if( compare_prefix_dir( name, filename ) ||
+ compare_tslash( name, filename ) )
+ { skip = false; name_pending[i] = false; break; }
+ }
+
+ if( extended.size == 0 &&
+ ( typeflag == tf_regular || typeflag == tf_hiperf ) )
+ extended.size = strtoull( header + size_o, 0, 8 );
- const Typeflag typeflag = (Typeflag)header[typeflag_o];
- const unsigned long long file_size =
- ( typeflag == tf_regular || typeflag == tf_hiperf ) ?
- strtoull( header + size_o, 0, 8 ) : 0;
if( listing || skip )
- retval = list_member( infd, filename, file_size, header, skip );
+ retval = list_member( infd, extended, header, skip );
else
- retval = extract_member( infd, filename, file_size, header );
- if( retval ) return retval;
+ retval = extract_member( infd, extended, header, keep_damaged );
+ extended.reset();
+ if( retval )
+ { show_error( "Error is not recoverable: exiting now." );
+ return retval; }
}
for( int i = 0; i < parser.arguments(); ++i )
diff --git a/main.cc b/main.cc
index 19a6d31..69c46b4 100644
--- a/main.cc
+++ b/main.cc
@@ -40,6 +40,7 @@
#if defined(__OS2__)
#include <io.h>
#endif
+#include <lzlib.h>
#include "arg_parser.h"
#include "tarlz.h"
@@ -56,21 +57,33 @@ int verbosity = 0;
namespace {
-const char * const Program_name = "Tarlz";
const char * const program_name = "tarlz";
const char * const program_year = "2018";
const char * invocation_name = 0;
-enum Mode { m_none, m_append, m_create, m_extract, m_list };
+enum Mode { m_none, m_append, m_concatenate, m_create, m_extract, m_list };
void show_help()
{
- std::printf( "%s - Archiver with multimember lzip compression.\n", Program_name );
- std::printf( "\nUsage: %s [options] [files]\n", invocation_name );
+ std::printf( "Tarlz is a small and simple implementation of the tar archiver. By default\n"
+ "tarlz creates, lists and extracts archives in a simplified posix pax format\n"
+ "compressed with lzip on a per file basis. Each tar member is compressed in\n"
+ "its own lzip member, as well as the end-of-file blocks. This method is fully\n"
+ "backward compatible with standard tar tools like GNU tar, which treat the\n"
+ "resulting multimember tar.lz archive like any other tar.lz archive. Tarlz\n"
+ "can append files to the end of such compressed archives.\n"
+ "\nThe tarlz file format is a safe posix-style backup format. In case of\n"
+ "corruption, tarlz can extract all the undamaged members from the tar.lz\n"
+ "archive, skipping over the damaged members, just like the standard\n"
+ "(uncompressed) tar. Moreover, the option '--keep-damaged' can be used to\n"
+ "recover as much data as possible from each damaged member, and lziprecover\n"
+ "can be used to recover some of the damaged members.\n"
+ "\nUsage: %s [options] [files]\n", invocation_name );
std::printf( "\nOptions:\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"
+ " -A, --concatenate append tar.lz archives to the end of an archive\n"
" -c, --create create a new archive\n"
" -C, --directory=<dir> change to directory <dir>\n"
" -f, --file=<archive> use archive file <archive>\n"
@@ -82,10 +95,15 @@ void show_help()
" -0 .. -9 set compression level [default 6]\n"
" --asolid create solidly compressed appendable archive\n"
" --dsolid create per-directory compressed archive\n"
+ " --no-solid create per-file compressed archive (default)\n"
" --solid create solidly compressed archive\n"
- " --group=<group> use <group> name/id for added files\n"
- " --owner=<owner> use <owner> name/id for added files\n"
- " --uncompressed don't compress the created archive\n"
+ " --anonymous equivalent to '--owner=root --group=root'\n"
+ " --owner=<owner> use <owner> name/ID for files added\n"
+ " --group=<group> use <group> name/ID for files added\n"
+ " --keep-damaged don't delete partially extracted files\n"
+ " --missing-crc exit with error status if missing extended CRC\n"
+// " --permissive allow repeated extended headers and records\n"
+ " --uncompressed don't compress the archive created\n"
"\nExit status: 0 for a normal exit, 1 for environmental problems (file\n"
"not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or\n"
"invalid input file, 3 for an internal consistency error (eg, bug) which\n"
@@ -99,6 +117,7 @@ void show_version()
{
std::printf( "%s %s\n", program_name, PROGVERSION );
std::printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year );
+ std::printf( "Using lzlib %s\n", LZ_version() );
std::printf( "License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n" );
@@ -280,39 +299,53 @@ int main( const int argc, const char * const argv[] )
std::string archive_name;
Mode program_mode = m_none;
int level = 6; // compression level, < 0 = uncompressed
+ bool keep_damaged = false;
+ bool missing_crc = false;
+ bool permissive = false;
invocation_name = argv[0];
- enum { opt_aso = 256, opt_dso, opt_grp, opt_own, opt_sol, opt_un };
+ if( LZ_version()[0] < '1' )
+ { show_error( "Bad library version. At least lzlib 1.0 is required." );
+ return 1; }
+
+ enum { opt_ano = 256, opt_aso, opt_crc, opt_dso, opt_grp, opt_kd, opt_nso,
+ opt_own, opt_per, opt_sol, opt_un };
const Arg_parser::Option options[] =
{
- { '0', 0, Arg_parser::no },
- { '1', 0, Arg_parser::no },
- { '2', 0, Arg_parser::no },
- { '3', 0, Arg_parser::no },
- { '4', 0, Arg_parser::no },
- { '5', 0, Arg_parser::no },
- { '6', 0, Arg_parser::no },
- { '7', 0, Arg_parser::no },
- { '8', 0, Arg_parser::no },
- { '9', 0, Arg_parser::no },
- { 'c', "create", Arg_parser::no },
- { 'C', "directory", Arg_parser::yes },
- { 'f', "file", Arg_parser::yes },
- { 'h', "help", Arg_parser::no },
- { 'H', "format", Arg_parser::yes },
- { 'q', "quiet", Arg_parser::no },
- { 'r', "append", Arg_parser::no },
- { 't', "list", Arg_parser::no },
- { 'v', "verbose", Arg_parser::no },
- { 'V', "version", Arg_parser::no },
- { 'x', "extract", Arg_parser::no },
- { opt_aso, "asolid", Arg_parser::no },
- { opt_dso, "dsolid", Arg_parser::no },
- { opt_grp, "group", Arg_parser::yes },
- { opt_own, "owner", Arg_parser::yes },
- { opt_sol, "solid", Arg_parser::no },
- { opt_un, "uncompressed", Arg_parser::no },
- { 0 , 0, Arg_parser::no } };
+ { '0', 0, Arg_parser::no },
+ { '1', 0, Arg_parser::no },
+ { '2', 0, Arg_parser::no },
+ { '3', 0, Arg_parser::no },
+ { '4', 0, Arg_parser::no },
+ { '5', 0, Arg_parser::no },
+ { '6', 0, Arg_parser::no },
+ { '7', 0, Arg_parser::no },
+ { '8', 0, Arg_parser::no },
+ { '9', 0, Arg_parser::no },
+ { 'A', "concatenate", Arg_parser::no },
+ { 'c', "create", Arg_parser::no },
+ { 'C', "directory", Arg_parser::yes },
+ { 'f', "file", Arg_parser::yes },
+ { 'h', "help", Arg_parser::no },
+ { 'H', "format", Arg_parser::yes },
+ { 'q', "quiet", Arg_parser::no },
+ { 'r', "append", Arg_parser::no },
+ { 't', "list", Arg_parser::no },
+ { 'v', "verbose", Arg_parser::no },
+ { 'V', "version", Arg_parser::no },
+ { 'x', "extract", Arg_parser::no },
+ { opt_ano, "anonymous", Arg_parser::no },
+ { opt_aso, "asolid", Arg_parser::no },
+ { opt_dso, "dsolid", Arg_parser::no },
+ { opt_grp, "group", Arg_parser::yes },
+ { opt_kd, "keep-damaged", Arg_parser::no },
+ { opt_crc, "missing-crc", Arg_parser::no },
+ { opt_nso, "no-solid", Arg_parser::no },
+ { opt_own, "owner", Arg_parser::yes },
+ { opt_per, "permissive", Arg_parser::no },
+ { opt_sol, "solid", Arg_parser::no },
+ { opt_un, "uncompressed", Arg_parser::no },
+ { 0 , 0, Arg_parser::no } };
const Arg_parser parser( argc, argv, options, true );
if( parser.error().size() ) // bad option
@@ -330,6 +363,7 @@ int main( const int argc, const char * const argv[] )
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
level = code - '0'; break;
+ case 'A': set_mode( program_mode, m_concatenate ); break;
case 'c': set_mode( program_mode, m_create ); break;
case 'C': break; // skip chdir
case 'f': if( sarg != "-" ) archive_name = sarg; break;
@@ -341,12 +375,17 @@ int main( const int argc, const char * const argv[] )
case 'v': if( verbosity < 4 ) ++verbosity; break;
case 'V': show_version(); return 0;
case 'x': set_mode( program_mode, m_extract ); break;
+ case opt_ano: set_owner( "root" ); set_group( "root" ); break;
case opt_aso: cl_solid = 2; break;
+ case opt_crc: missing_crc = true; break;
case opt_dso: cl_solid = 1; break;
case opt_grp: set_group( arg ); break;
+ case opt_kd: keep_damaged = true; break;
+ case opt_nso: cl_solid = 0; break;
case opt_own: set_owner( arg ); break;
+ case opt_per: permissive = true; break;
case opt_sol: cl_solid = 3; break;
- case opt_un: level = -1; break;
+ case opt_un: level = -1; break;
default : internal_error( "uncaught option" );
}
} // end process options
@@ -358,12 +397,14 @@ int main( const int argc, const char * const argv[] )
switch( program_mode )
{
- case m_none: show_error( "Missing operation.", 0, true ); return 2;
+ case m_none: show_error( "Missing operation.", 0, true ); return 2;
case m_append:
case m_create: return encode( archive_name, parser, filenames, level,
program_mode == m_append );
+ case m_concatenate: return concatenate( archive_name, parser, filenames );
case m_extract:
- case m_list:
- return decode( archive_name, parser, filenames, program_mode == m_list );
+ case m_list: return decode( archive_name, parser, filenames,
+ keep_damaged, program_mode == m_list,
+ missing_crc, permissive );
}
}
diff --git a/tarlz.h b/tarlz.h
index 3bb10c9..bc84c53 100644
--- a/tarlz.h
+++ b/tarlz.h
@@ -32,7 +32,8 @@ enum Lengths {
enum Typeflag {
tf_regular = '0', tf_link = '1', tf_symlink = '2', tf_chardev = '3',
- tf_blockdev = '4', tf_directory = '5', tf_fifo = '6', tf_hiperf = '7' };
+ tf_blockdev = '4', tf_directory = '5', tf_fifo = '6', tf_hiperf = '7',
+ tf_extended = 'x' };
const uint8_t ustar_magic[magic_l] =
{ 0x75, 0x73, 0x74, 0x61, 0x72, 0 }; // "ustar\0"
@@ -41,6 +42,68 @@ inline bool verify_ustar_magic( const uint8_t * const buf )
{ return std::memcmp( buf + magic_o, ustar_magic, magic_l ) == 0; }
+class CRC32C // Uses CRC32-C (Castagnoli) polynomial.
+ {
+ uint32_t data[256]; // Table of CRCs of all 8-bit messages.
+
+public:
+ CRC32C()
+ {
+ for( unsigned n = 0; n < 256; ++n )
+ {
+ unsigned c = n;
+ for( int k = 0; k < 8; ++k )
+ { if( c & 1 ) c = 0x82F63B78U ^ ( c >> 1 ); else c >>= 1; }
+ data[n] = c;
+ }
+ }
+
+ void update_buf( uint32_t & crc, const uint8_t * const buffer,
+ const int size ) const
+ {
+ uint32_t c = crc;
+ for( int i = 0; i < size; ++i )
+ c = data[(c^buffer[i])&0xFF] ^ ( c >> 8 );
+ crc = c;
+ }
+
+ // Calculates the crc of size bytes except a window of 8 bytes at pos
+ uint32_t windowed_crc( const uint8_t * const buffer, const int pos,
+ const int size ) const
+ {
+ uint32_t crc = 0xFFFFFFFFU;
+ update_buf( crc, buffer, pos );
+ update_buf( crc, buffer + pos + 8, size - pos - 8 );
+ return crc ^ 0xFFFFFFFFU;
+ }
+ };
+
+extern const CRC32C crc32c;
+
+
+// Round "size" to the next multiple of header size (512).
+//
+inline unsigned long long round_up( unsigned long long size )
+ {
+ const int rem = size % header_size;
+ const int padding = rem ? header_size - rem : 0;
+ return size + padding;
+ }
+
+
+struct Extended // stores metadata from/for extended records
+ {
+ std::string linkpath;
+ std::string path;
+ unsigned long long size;
+ bool crc_present;
+ Extended() : size( 0 ), crc_present( false ) {}
+ void reset()
+ { linkpath.clear(); path.clear(); size = 0; crc_present = false; }
+ bool empty() { return linkpath.empty() && path.empty() && size == 0; }
+ bool parse( const int infd, const Tar_header header, const bool permissive );
+ };
+
// defined in create.cc
extern int cl_owner;
extern int cl_group;
@@ -48,12 +111,15 @@ extern int cl_solid;
unsigned ustar_chksum( const uint8_t * const buf );
bool verify_ustar_chksum( const uint8_t * const buf );
class Arg_parser;
+int concatenate( const std::string & archive_name, const Arg_parser & parser,
+ const int filenames );
int encode( const std::string & archive_name, const Arg_parser & parser,
const int filenames, const int level, const bool append );
// defined in extract.cc
int decode( const std::string & archive_name, const Arg_parser & parser,
- const int filenames, const bool listing );
+ const int filenames, const bool keep_damaged, const bool listing,
+ const bool missing_crc, const bool permissive );
// defined in main.cc
extern int verbosity;
diff --git a/testsuite/check.sh b/testsuite/check.sh
index 07b0d34..6bdf2d7 100755
--- a/testsuite/check.sh
+++ b/testsuite/check.sh
@@ -32,9 +32,16 @@ in="${testdir}"/test.txt
in_lz="${testdir}"/test.txt.lz
in_tar="${testdir}"/test.txt.tar
in_tar_lz="${testdir}"/test.txt.tar.lz
+inbad1="${testdir}"/test_bad1.txt
+inbad2="${testdir}"/test_bad2.txt
test3="${testdir}"/test3.tar
test3_lz="${testdir}"/test3.tar.lz
-test3a_lz="${testdir}"/test3a.tar.lz
+test3dir_lz="${testdir}"/test3_dir.tar.lz
+test3dot_lz="${testdir}"/test3_dot.tar.lz
+t155="${testdir}"/t155.tar
+t155_lz="${testdir}"/t155.tar.lz
+tlzit1="${testdir}"/tlz_in_tar1.tar
+tlzit2="${testdir}"/tlz_in_tar2.tar
bad1="${testdir}"/test3_bad1.tar
bad2="${testdir}"/test3_bad2.tar
bad3="${testdir}"/test3_bad3.tar
@@ -48,10 +55,19 @@ bad5_lz="${testdir}"/test3_bad5.tar.lz
bad6_lz="${testdir}"/test3_bad6.tar.lz
eof_lz="${testdir}"/eof.tar.lz
fail=0
+lwarn=0
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
+lzlib_1_11() { [ ${lwarn} = 0 ] &&
+ printf "\nwarning: testing --keep-damaged requires lzlib-1.11-rc2 or newer\n$1"
+ lwarn=1 ; }
-# Description of test files for lziprecover:
+# Description of test files for tarlz:
+# t155.tar[.lz] directory + file + link + eof, all with 155 char names
+# test_bad1.tar.lz: truncated at offset 6000 (of 7495)
+# test_bad2.tar.lz: byte at offset 6000 changed from 0x56 to 0x46
# test3.tar: 3 members (foo bar baz) + 2 zeroed 512-byte blocks
+# test3_dir.tar.lz: like test3.tar.lz but members /dir/foo /dir/bar /dir/baz
+# test3_dot.tar.lz: like test3.tar.lz but members ./foo ./bar ./baz
# test3_bad1.tar: byte at offset 259 changed from 't' to '0' (magic)
# test3_bad2.tar: byte at offset 1283 changed from 't' to '0' (magic)
# test3_bad3.tar: byte at offset 2559 changed from 0x00 to 0x20 (padding)
@@ -60,137 +76,191 @@ test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
# test3_bad5.tar: 510 zeros + "LZ" prepended to test3.tar (bogus lz header)
# test3_bad1.tar.lz: byte at offset 2 changed from 'I' to 'i' (magic)
# test3_bad2.tar.lz: byte at offset 49 changed from 0x49 to 0x69 (mid stream)
-# test3_bad3.tar.lz: byte at offset 149 changed from 0x2D to 0x3D (mid stream)
+# test3_bad3.tar.lz: byte at offset 176 changed from 0x7D to 0x6D (mid stream)
# test3_bad4.tar.lz: combined damage of test3_bad2.tar.lz and test3_bad3.tar.lz
# test3_bad5.tar.lz: [71-134] --> zeroed (first trailer + seconf header)
# test3_bad6.tar.lz: 510 zeros prepended to test3.tar.lz (header in two blocks)
+# tlz_in_tar1.tar: 1 member (test3.tar.lz) first magic damaged
+# tlz_in_tar2.tar: 2 members (foo test3.tar.lz) first magic damaged
+# ug32chars.tar.lz: 1 member (foo) with 32-character owner and group names
printf "testing tarlz-%s..." "$2"
-"${TARLZ}" -qtf ${in}
+"${TARLZ}" -q -tf "${in}"
[ $? = 2 ] || test_failed $LINENO
-"${TARLZ}" -qtf ${in_lz}
+"${TARLZ}" -q -tf "${in_lz}"
[ $? = 2 ] || test_failed $LINENO
-"${TARLZ}" -qtf nx_file
+"${TARLZ}" -q -tf nx_file
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -tf 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qcf out.tar.lz
+"${TARLZ}" -q -cf out.tar.lz
[ $? = 1 ] || test_failed $LINENO
[ ! -e out.tar.lz ] || test_failed $LINENO
"${TARLZ}" -rf out.tar.lz || test_failed $LINENO
[ ! -e out.tar.lz ] || test_failed $LINENO
-"${TARLZ}" -qrf - ${in}
+"${TARLZ}" -q -rf - "${in}"
[ $? = 1 ] || test_failed $LINENO
[ ! -e - ] || test_failed $LINENO
-"${TARLZ}" -qr ${in}
+"${TARLZ}" -q -r "${in}"
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" --uncompressed -qrf out.tar ${in}
+"${TARLZ}" --uncompressed -q -rf out.tar "${in}"
[ $? = 1 ] || test_failed $LINENO
[ ! -e out.tar ] || test_failed $LINENO
-cat ${test3_lz} > test.tar.lz || framework_failure
-"${TARLZ}" --uncompressed -qrf test.tar.lz ${in}
+cat "${test3_lz}" > test.tar.lz || framework_failure
+"${TARLZ}" --uncompressed -q -rf test.tar.lz "${in}"
[ $? = 1 ] || test_failed $LINENO
-cmp ${test3_lz} test.tar.lz || test_failed $LINENO
+cmp "${test3_lz}" test.tar.lz || test_failed $LINENO
rm -f test.tar.lz || framework_failure
-cat ${test3} > test.tar || framework_failure
-"${TARLZ}" -qrf test.tar ${in}
+cat "${test3}" > test.tar || framework_failure
+"${TARLZ}" -q -rf test.tar "${in}"
[ $? = 2 ] || test_failed $LINENO
-cmp ${test3} test.tar || test_failed $LINENO
+cmp "${test3}" test.tar || test_failed $LINENO
rm -f test.tar || framework_failure
-"${TARLZ}" -qc ${in} nx_file > /dev/null
+"${TARLZ}" -q -c "${in}" nx_file > /dev/null
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qc -C nx_dir ${in}
+"${TARLZ}" -q -c -C nx_dir "${in}"
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qx -C nx_dir ${test3_lz}
+"${TARLZ}" -q -x -C nx_dir "${test3_lz}"
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qcr
+"${TARLZ}" -q -cr
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qct
+"${TARLZ}" -q -ct
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qcx
+"${TARLZ}" -q -cx
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qtx
+"${TARLZ}" -q -tx
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -qctx
+"${TARLZ}" -q -ctx
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" --help > /dev/null || test_failed $LINENO
"${TARLZ}" -V > /dev/null || test_failed $LINENO
-"${TARLZ}" --bad_option -tf ${test3_lz} 2> /dev/null
+"${TARLZ}" --bad_option -tf "${test3_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -tf 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" --owner=invalid_oner_name -tf ${test3_lz} 2> /dev/null
+"${TARLZ}" --owner=invalid_oner_name -tf "${test3_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" --group=invalid_goup_name -tf ${test3_lz} 2> /dev/null
+"${TARLZ}" --group=invalid_goup_name -tf "${test3_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
-"${TARLZ}" -tf ${eof_lz} || test_failed $LINENO
-"${TARLZ}" -xf ${eof_lz} || test_failed $LINENO
-"${TARLZ}" -tf ${in_tar_lz} > /dev/null || test_failed $LINENO
-"${TARLZ}" -xf ${in_tar_lz} || test_failed $LINENO
-cmp ${in} test.txt || test_failed $LINENO
+# test --list and --extract
+"${TARLZ}" -tf "${eof_lz}" --missing-crc || test_failed $LINENO
+"${TARLZ}" -xf "${eof_lz}" --missing-crc || test_failed $LINENO
+"${TARLZ}" -tf "${in_tar_lz}" --missing-crc > /dev/null || test_failed $LINENO
+"${TARLZ}" -xf "${in_tar_lz}" --missing-crc || test_failed $LINENO
+cmp "${in}" test.txt || test_failed $LINENO
rm -f test.txt || framework_failure
-"${TARLZ}" -C nx_dir -tf ${in_tar} > /dev/null || test_failed $LINENO
-"${TARLZ}" -xf ${in_tar} || test_failed $LINENO
-cmp ${in} test.txt || test_failed $LINENO
+"${TARLZ}" -C nx_dir -tf "${in_tar}" > /dev/null || test_failed $LINENO
+"${TARLZ}" -xf "${in_tar}" --missing-crc || test_failed $LINENO
+cmp "${in}" test.txt || test_failed $LINENO
rm -f test.txt || framework_failure
+printf "foo\n" > cfoo || framework_failure
+printf "bar\n" > cbar || framework_failure
+printf "baz\n" > cbaz || framework_failure
rm -f foo bar baz || framework_failure
-"${TARLZ}" -xf ${test3_lz} || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+"${TARLZ}" -xf "${test3_lz}" --missing-crc || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -xf ${test3} || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+"${TARLZ}" -q -xf "${test3_lz}" ./foo ./bar ./baz || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${test3a_lz} || test_failed $LINENO
-[ -e dir/foo ] || test_failed $LINENO
-[ -e dir/bar ] || test_failed $LINENO
-[ -e dir/baz ] || test_failed $LINENO
+"${TARLZ}" -xf "${test3}" --missing-crc || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+rm -f foo bar baz || framework_failure
+"${TARLZ}" -q -xf "${test3dot_lz}" --missing-crc || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+rm -f foo bar baz || framework_failure
+"${TARLZ}" -q -xf "${test3dot_lz}" foo bar baz || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+rm -f foo bar baz || framework_failure
+"${TARLZ}" -q -xf "${test3dir_lz}" --missing-crc || test_failed $LINENO
+cmp cfoo dir/foo || test_failed $LINENO
+cmp cbar dir/bar || test_failed $LINENO
+cmp cbaz dir/baz || test_failed $LINENO
+rm -rf dir || framework_failure
+"${TARLZ}" -q -xf "${test3dir_lz}" dir/foo dir/bar dir/baz || test_failed $LINENO
+cmp cfoo dir/foo || test_failed $LINENO
+cmp cbar dir/bar || test_failed $LINENO
+cmp cbaz dir/baz || test_failed $LINENO
rm -rf dir || framework_failure
-cat ${in} > test.txt || framework_failure
+# test --concatenate
+cat "${in_tar_lz}" > out.tar.lz || framework_failure
+"${TARLZ}" -Af out.tar.lz "${test3_lz}" || test_failed $LINENO
+"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
+cmp "${in}" test.txt || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+touch aout.tar.lz || framework_failure # concatenate to empty file
+"${TARLZ}" -Af aout.tar.lz "${in_tar_lz}" "${test3_lz}" || test_failed $LINENO
+cmp out.tar.lz aout.tar.lz || test_failed $LINENO
+cat "${in_tar_lz}" > aout.tar.lz || framework_failure
+"${TARLZ}" -Aqf aout.tar.lz "${test3_lz}" "${test3}"
+[ $? = 2 ] || test_failed $LINENO
+cmp out.tar.lz aout.tar.lz || test_failed $LINENO
+rm -f test.txt foo bar baz out.tar.lz aout.tar.lz || framework_failure
+
+# test --create
+cat "${in}" > test.txt || framework_failure
"${TARLZ}" -0 -cf out.tar.lz test.txt || test_failed $LINENO
rm -f test.txt || framework_failure
-"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
-cmp ${in} test.txt || test_failed $LINENO
-cat ${in} > test.txt || framework_failure
+"${TARLZ}" -xf out.tar.lz --missing-crc || test_failed $LINENO
+cmp "${in}" test.txt || test_failed $LINENO
+cat "${in}" > test.txt || framework_failure
"${TARLZ}" --uncompressed -cf out.tar test.txt || test_failed $LINENO
rm -f test.txt || framework_failure
-"${TARLZ}" -xf out.tar || test_failed $LINENO
-cmp ${in} test.txt || test_failed $LINENO
+"${TARLZ}" -xf out.tar --missing-crc || test_failed $LINENO
+cmp "${in}" test.txt || test_failed $LINENO
rm -f test.txt out.tar out.tar.lz || framework_failure
-printf "foo" > foo || framework_failure
+cat cfoo > foo || framework_failure
rm -f bar || framework_failure
-printf "baz" > baz || framework_failure
-"${TARLZ}" -qcf out.tar.lz foo bar baz
+cat cbaz > baz || framework_failure
+"${TARLZ}" -q -cf out.tar.lz foo bar baz
[ $? = 1 ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
+"${TARLZ}" -xf out.tar.lz --missing-crc || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf out.tar.lz bar
+"${TARLZ}" -q -xf out.tar.lz bar
[ $? = 1 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f out.tar.lz || framework_failure
-printf "foo" > foo || framework_failure
-printf "bar" > bar || framework_failure
-printf "baz" > baz || framework_failure
+cat cfoo > foo || framework_failure
+cat cbar > bar || framework_failure
+cat cbaz > baz || framework_failure
"${TARLZ}" -0 -cf out.tar.lz foo bar baz || test_failed $LINENO
+"${TARLZ}" -0 -q -cf aout.tar.lz foo bar aout.tar.lz baz || test_failed $LINENO
+cmp out.tar.lz aout.tar.lz || test_failed $LINENO
+"${TARLZ}" -q -Af aout.tar.lz aout.tar.lz || test_failed $LINENO
+cmp out.tar.lz aout.tar.lz || test_failed $LINENO
+"${TARLZ}" -q -rf aout.tar.lz aout.tar.lz || test_failed $LINENO
+cmp out.tar.lz aout.tar.lz || test_failed $LINENO
+rm -f aout.tar.lz || framework_failure
+
+# test --append
"${TARLZ}" --dsolid -0 -cf aout.tar.lz foo bar baz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f aout.tar.lz || framework_failure
-"${TARLZ}" -0 -qcf aout.tar.lz foo/ ./bar ./baz/ || test_failed $LINENO
+"${TARLZ}" -0 -q -cf aout.tar.lz foo/ ./bar ./baz/ || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f aout.tar.lz || framework_failure
"${TARLZ}" -0 -cf aout.tar.lz foo || test_failed $LINENO
@@ -204,51 +274,49 @@ cmp out.tar.lz aout.tar.lz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -rf aout.tar.lz -C nx_dir || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
-"${TARLZ}" -0 -qrf aout.tar.lz nx_file
+"${TARLZ}" -0 -q -rf aout.tar.lz nx_file
[ $? = 1 ] || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
-cat ${eof_lz} > aout.tar.lz || framework_failure # append to empty archive
+cat "${eof_lz}" > aout.tar.lz || framework_failure # append to empty archive
"${TARLZ}" -0 -rf aout.tar.lz foo bar baz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
-mv -f foo foo.orig || framework_failure
-mv -f bar bar.orig || framework_failure
-mv -f baz baz.orig || framework_failure
+rm -f foo bar baz || framework_failure
"${TARLZ}" -xf out.tar.lz foo/ bar// baz/// || test_failed $LINENO
-cmp foo foo.orig || test_failed $LINENO
-cmp bar bar.orig || test_failed $LINENO
-cmp baz baz.orig || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
-cmp foo foo.orig || test_failed $LINENO
-cmp bar bar.orig || test_failed $LINENO
-cmp baz baz.orig || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
mkdir dir1 || framework_failure
"${TARLZ}" -C dir1 -xf out.tar.lz || test_failed $LINENO
-cmp dir1/foo foo.orig || test_failed $LINENO
-cmp dir1/bar bar.orig || test_failed $LINENO
-cmp dir1/baz baz.orig || test_failed $LINENO
+cmp cfoo dir1/foo || test_failed $LINENO
+cmp cbar dir1/bar || test_failed $LINENO
+cmp cbaz dir1/baz || test_failed $LINENO
rm -f aout.tar.lz foo bar baz || framework_failure
"${TARLZ}" -C dir1 -0 -cf aout.tar.lz foo bar baz || test_failed $LINENO
"${TARLZ}" -xf aout.tar.lz || test_failed $LINENO
-cmp foo foo.orig || test_failed $LINENO
-cmp bar bar.orig || test_failed $LINENO
-cmp baz baz.orig || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f aout.tar.lz foo bar baz || framework_failure
"${TARLZ}" -C dir1 -0 -c foo bar baz | "${TARLZ}" -x || test_failed $LINENO
-cmp foo foo.orig || test_failed $LINENO
-cmp bar bar.orig || test_failed $LINENO
-cmp baz baz.orig || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f dir1/foo dir1/bar dir1/baz || framework_failure
"${TARLZ}" -0 -c foo bar baz | "${TARLZ}" -C dir1 -x || test_failed $LINENO
-cmp dir1/foo foo.orig || test_failed $LINENO
-cmp dir1/bar bar.orig || test_failed $LINENO
-cmp dir1/baz baz.orig || test_failed $LINENO
+cmp cfoo dir1/foo || test_failed $LINENO
+cmp cbar dir1/bar || test_failed $LINENO
+cmp cbaz dir1/baz || test_failed $LINENO
rm -f dir1/foo dir1/bar dir1/baz || framework_failure
"${TARLZ}" -0 -c foo bar baz | "${TARLZ}" -x foo bar baz -C dir1 ||
test_failed $LINENO
-cmp dir1/foo foo.orig || test_failed $LINENO
-cmp dir1/bar bar.orig || test_failed $LINENO
-cmp dir1/baz baz.orig || test_failed $LINENO
+cmp cfoo dir1/foo || test_failed $LINENO
+cmp cbar dir1/bar || test_failed $LINENO
+cmp cbaz dir1/baz || test_failed $LINENO
rm -f foo dir1/bar baz || framework_failure
"${TARLZ}" -0 -cf aout.tar.lz -C dir1 foo -C .. bar -C dir1 baz ||
test_failed $LINENO
@@ -256,22 +324,23 @@ cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -cf aout.tar.lz dir1/foo dir1/baz || test_failed $LINENO
rm -rf dir1 || framework_failure
"${TARLZ}" -xf aout.tar.lz dir1 || test_failed $LINENO
-cmp dir1/foo foo.orig || test_failed $LINENO
-cmp dir1/baz baz.orig || test_failed $LINENO
+cmp cfoo dir1/foo || test_failed $LINENO
+cmp cbaz dir1/baz || test_failed $LINENO
rm -rf dir1 || framework_failure
rm -f out.tar.lz aout.tar.lz || framework_failure
# append to solid archive
-printf "foo" > foo || framework_failure
-printf "bar" > bar || framework_failure
-printf "baz" > baz || framework_failure
+cat cfoo > foo || framework_failure
+cat cbar > bar || framework_failure
+cat cbaz > baz || framework_failure
"${TARLZ}" --solid -0 -cf out.tar.lz foo || test_failed $LINENO
+cat out.tar.lz > aout.tar.lz || framework_failure
for i in --asolid --dsolid --solid -0 ; do
- "${TARLZ}" $i -qrf out.tar.lz bar baz
+ "${TARLZ}" $i -q -rf out.tar.lz bar baz
[ $? = 2 ] || test_failed $LINENO $i
- [ -e out.tar.lz ] || test_failed $LINENO $i
+ cmp out.tar.lz aout.tar.lz || test_failed $LINENO $i
done
-rm -f out.tar.lz || framework_failure
+rm -f out.tar.lz aout.tar.lz || framework_failure
for i in --asolid --dsolid -0 ; do
for j in --asolid --dsolid --solid -0 ; do
"${TARLZ}" $i -0 -cf out.tar.lz foo ||
@@ -280,14 +349,15 @@ for i in --asolid --dsolid -0 ; do
test_failed $LINENO "$i $j"
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf out.tar.lz || test_failed $LINENO "$i $j"
- cmp foo foo.orig || test_failed $LINENO "$i $j"
- cmp bar bar.orig || test_failed $LINENO "$i $j"
- cmp baz baz.orig || test_failed $LINENO "$i $j"
+ cmp cfoo foo || test_failed $LINENO "$i $j"
+ cmp cbar bar || test_failed $LINENO "$i $j"
+ cmp cbaz baz || test_failed $LINENO "$i $j"
rm -f out.tar.lz || framework_failure
done
done
-rm -f foo foo.orig bar bar.orig baz baz.orig || framework_failure
+rm -f foo bar baz || framework_failure
+# test directories and links
mkdir dir1 || framework_failure
"${TARLZ}" -0 -cf out.tar dir1 || test_failed $LINENO
rmdir dir1 || framework_failure
@@ -302,131 +372,222 @@ rmdir dir1 || framework_failure
rmdir dir1
rm -f out.tar || framework_failure
-if ln ${in} dummy_link 2> /dev/null &&
- ln -s ${in} dummy_slink 2> /dev/null ; then
+touch dummy_file || framework_failure
+if ln dummy_file dummy_link 2> /dev/null &&
+ ln -s dummy_file dummy_slink 2> /dev/null ; then
+ ln_works=yes
name_100=name_100_bytes_long_nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
path_100=dir1/dir2/dir3/path_100_bytes_long_nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
path_106=dir1/dir2/dir3/path_longer_than_100_bytes_nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
mkdir dir1 || framework_failure
mkdir dir1/dir2 || framework_failure
mkdir dir1/dir2/dir3 || framework_failure
- cat ${in} > dir1/dir2/dir3/in || framework_failure
- ln dir1/dir2/dir3/in dir1/dir2/dir3/${name_100} || framework_failure
- ln dir1/dir2/dir3/in ${path_100} || framework_failure
- ln dir1/dir2/dir3/in ${path_106} || framework_failure
+ cat "${in}" > dir1/dir2/dir3/in || framework_failure
+ ln dir1/dir2/dir3/in dir1/dir2/dir3/"${name_100}" || framework_failure
+ ln dir1/dir2/dir3/in "${path_100}" || framework_failure
+ ln dir1/dir2/dir3/in "${path_106}" || framework_failure
ln -s in dir1/dir2/dir3/link || framework_failure
- ln -s ${name_100} dir1/dir2/dir3/link_100 || framework_failure
+ ln -s "${name_100}" dir1/dir2/dir3/link_100 || framework_failure
"${TARLZ}" -0 -cf out.tar dir1 || test_failed $LINENO
rm -rf dir1 || framework_failure
"${TARLZ}" -xf out.tar || test_failed $LINENO
- cmp ${in} dir1/dir2/dir3/in || test_failed $LINENO
- cmp ${in} dir1/dir2/dir3/${name_100} || test_failed $LINENO
- cmp ${in} ${path_100} || test_failed $LINENO
- cmp ${in} ${path_106} || test_failed $LINENO
- cmp ${in} dir1/dir2/dir3/link || test_failed $LINENO
- cmp ${in} dir1/dir2/dir3/link_100 || test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/in || test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/"${name_100}" || test_failed $LINENO
+ cmp "${in}" "${path_100}" || test_failed $LINENO
+ cmp "${in}" "${path_106}" || test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/link || test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/link_100 || test_failed $LINENO
rm -f dir1/dir2/dir3/in || framework_failure
- cmp ${in} dir1/dir2/dir3/link 2> /dev/null && test_failed $LINENO
- cmp ${in} dir1/dir2/dir3/link_100 || test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/link 2> /dev/null && test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/link_100 || test_failed $LINENO
"${TARLZ}" -xf out.tar || test_failed $LINENO
rm -f out.tar || framework_failure
- cmp ${in} dir1/dir2/dir3/in || test_failed $LINENO
- cmp ${in} dir1/dir2/dir3/link || test_failed $LINENO
- "${TARLZ}" -0 -qc ../tmp/dir1 > /dev/null || test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/in || test_failed $LINENO
+ cmp "${in}" dir1/dir2/dir3/link || test_failed $LINENO
+ "${TARLZ}" -0 -q -c ../tmp/dir1 > /dev/null || test_failed $LINENO
rm -rf dir1 || framework_failure
else
printf "\nwarning: skipping link test: 'ln' does not work on your system."
fi
-rm -f dummy_link dummy_slink || framework_failure
+rm -f dummy_slink dummy_link dummy_file || framework_failure
+
+printf "\ntesting long names..."
+
+"${TARLZ}" -q -tf "${t155}" || test_failed $LINENO
+"${TARLZ}" -q -tf "${t155_lz}" || test_failed $LINENO
+if [ "${ln_works}" = yes ] ; then
+ mkdir dir1 || framework_failure
+ "${TARLZ}" -C dir1 -xf "${t155}" || test_failed $LINENO
+ mkdir dir2 || framework_failure
+ "${TARLZ}" -C dir2 -xf "${t155_lz}" || test_failed $LINENO
+ diff -r dir1 dir2 || test_failed $LINENO
+ rmdir dir2 2> /dev/null && test_failed $LINENO
+ rmdir dir1 2> /dev/null && test_failed $LINENO
+ rm -rf dir2 dir1 || framework_failure
+fi
+
+"${TARLZ}" -tvf "${testdir}"/ug32chars.tar.lz | grep -q \
+ -e very_long_owner_name_of_32_chars/very_long_group_name_of_32_chars ||
+ test_failed $LINENO
+"${TARLZ}" -tvf "${testdir}"/ug32chars.tar.lz | grep -q \
+ -e very_long_owner_name_of_32_charsvery_long_group_name_of_32_chars &&
+ test_failed $LINENO
+"${TARLZ}" -tvf "${testdir}"/ug32chars.tar.lz | grep -q \
+ -e very_long_group_name_of_32_chars/very_long_group_name_of_32_chars &&
+ test_failed $LINENO
+"${TARLZ}" -xf "${testdir}"/ug32chars.tar.lz || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+rm -f foo || framework_failure
+
+printf "\ntesting bad input..."
-"${TARLZ}" -qxf "${testdir}"/dotdot1.tar.lz || test_failed $LINENO
+"${TARLZ}" -q -xf "${testdir}"/dotdot1.tar.lz || test_failed $LINENO
[ ! -e ../dir ] || test_failed $LINENO
-"${TARLZ}" -qxf "${testdir}"/dotdot2.tar.lz || test_failed $LINENO
+"${TARLZ}" -q -xf "${testdir}"/dotdot2.tar.lz || test_failed $LINENO
[ ! -e ../dir ] || test_failed $LINENO
-"${TARLZ}" -qxf "${testdir}"/dotdot3.tar.lz || test_failed $LINENO
+"${TARLZ}" -q -xf "${testdir}"/dotdot3.tar.lz || test_failed $LINENO
[ ! -e dir ] || test_failed $LINENO
-"${TARLZ}" -qxf "${testdir}"/dotdot4.tar.lz || test_failed $LINENO
+"${TARLZ}" -q -xf "${testdir}"/dotdot4.tar.lz || test_failed $LINENO
[ ! -e dir ] || test_failed $LINENO
-"${TARLZ}" -qxf "${testdir}"/dotdot5.tar.lz || test_failed $LINENO
+"${TARLZ}" -q -xf "${testdir}"/dotdot5.tar.lz || test_failed $LINENO
[ ! -e dir ] || test_failed $LINENO
-printf "\ntesting bad input..."
-
-dd if=${in_tar} of=truncated.tar bs=1000 count=1 2> /dev/null
-"${TARLZ}" -qtf truncated.tar > /dev/null
+dd if="${in_tar}" of=truncated.tar bs=1000 count=1 2> /dev/null
+"${TARLZ}" -q -tf truncated.tar > /dev/null
[ $? = 2 ] || test_failed $LINENO
-"${TARLZ}" -qxf truncated.tar
+"${TARLZ}" -q -xf truncated.tar
[ $? = 2 ] || test_failed $LINENO
[ ! -e test.txt ] || test_failed $LINENO
+rm -f truncated.tar || framework_failure
+# test compressed and --keep-damaged
+rm -f test.txt || framework_failure
+for i in "${inbad1}" "${inbad2}" ; do
+ "${TARLZ}" -q -xf "${i}.tar.lz"
+ [ $? = 2 ] || test_failed $LINENO "${i}"
+ [ ! -e test.txt ] || test_failed $LINENO "${i}"
+ rm -f test.txt || framework_failure
+ "${TARLZ}" -q -xf "${i}.tar.lz" --keep-damaged
+ [ $? = 2 ] || test_failed $LINENO "${i}"
+ [ -e test.txt ] || test_failed $LINENO "${i}"
+ cmp "${i}" test.txt 2> /dev/null || lzlib_1_11 "$LINENO ${i}"
+ rm -f test.txt || framework_failure
+done
+#
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad1_lz}
+"${TARLZ}" -q -xf "${bad1_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad2_lz}
+"${TARLZ}" -q -xf "${bad2_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad3_lz}
+"${TARLZ}" -q -xf "${bad3_lz}"
[ $? = 2 ] || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+rm -f foo bar baz || framework_failure
+"${TARLZ}" -q -xf "${bad3_lz}" --keep-damaged
+[ $? = 2 ] || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar 2> /dev/null || lzlib_1_11 $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad4_lz}
+"${TARLZ}" -q -xf "${bad4_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad5_lz}
+"${TARLZ}" -q -xf "${bad4_lz}" --keep-damaged
+[ $? = 2 ] || test_failed $LINENO
+[ ! -e foo ] || test_failed $LINENO
+cmp cbar bar 2> /dev/null || lzlib_1_11 $LINENO
+cmp cbaz baz || test_failed $LINENO
+rm -f foo bar baz || framework_failure
+"${TARLZ}" -q -xf "${bad5_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad6_lz}
+"${TARLZ}" -q -xf "${bad5_lz}" --keep-damaged
[ $? = 2 ] || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cfoo foo 2> /dev/null || lzlib_1_11 $LINENO
+[ ! -e bar ] || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+rm -f foo bar baz || framework_failure
+"${TARLZ}" -q -xf "${bad6_lz}"
+[ $? = 2 ] || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+# test uncompressed and --keep-damaged
+rm -f test.txt || framework_failure
+"${TARLZ}" -q -xf "${inbad1}.tar"
+[ $? = 2 ] || test_failed $LINENO
+[ ! -e test.txt ] || test_failed $LINENO
+rm -f test.txt || framework_failure
+"${TARLZ}" -q -xf "${inbad1}.tar" --keep-damaged
+[ $? = 2 ] || test_failed $LINENO
+[ -e test.txt ] || test_failed $LINENO
+cmp "${inbad1}" test.txt 2> /dev/null || test_failed $LINENO
+rm -f test.txt || framework_failure
+#
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad1}
+"${TARLZ}" -q -xf "${bad1}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad2}
+"${TARLZ}" -q -xf "${bad2}"
[ $? = 2 ] || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad3}
+"${TARLZ}" -q -xf "${bad3}"
[ $? = 2 ] || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad4}
+"${TARLZ}" -q -xf "${bad4}"
[ $? = 2 ] || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
+cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
-"${TARLZ}" -qxf ${bad5}
+"${TARLZ}" -q -xf "${bad5}"
[ $? = 2 ] || test_failed $LINENO
-[ -e foo ] || test_failed $LINENO
-[ -e bar ] || test_failed $LINENO
-[ -e baz ] || test_failed $LINENO
-rm -f foo bar baz || framework_failure
+cmp cfoo foo || test_failed $LINENO
+cmp cbar bar || test_failed $LINENO
+cmp cbaz baz || test_failed $LINENO
+rm -f cfoo cbar cbaz foo bar baz || framework_failure
+#
+rm -f test3.tar.lz || framework_failure
+"${TARLZ}" -q -xf "${tlzit1}"
+[ $? = 2 ] || test_failed $LINENO
+[ ! -e foo ] || test_failed $LINENO
+[ ! -e bar ] || test_failed $LINENO
+[ ! -e baz ] || test_failed $LINENO
+[ ! -e test3.tar.lz ] || test_failed $LINENO
+rm -f foo bar baz test3.tar.lz || framework_failure
+"${TARLZ}" -q -xf "${tlzit2}"
+[ $? = 2 ] || test_failed $LINENO
+[ ! -e foo ] || test_failed $LINENO
+[ ! -e bar ] || test_failed $LINENO
+[ ! -e baz ] || test_failed $LINENO
+cmp "${test3_lz}" test3.tar.lz || test_failed $LINENO
+rm -f foo bar baz test3.tar.lz || framework_failure
echo
if [ ${fail} = 0 ] ; then
diff --git a/testsuite/t155.tar b/testsuite/t155.tar
new file mode 100644
index 0000000..4a0f37b
--- /dev/null
+++ b/testsuite/t155.tar
Binary files differ
diff --git a/testsuite/t155.tar.lz b/testsuite/t155.tar.lz
new file mode 100644
index 0000000..3219071
--- /dev/null
+++ b/testsuite/t155.tar.lz
Binary files differ
diff --git a/testsuite/test3_bad3.tar.lz b/testsuite/test3_bad3.tar.lz
index c711a1a..3b46163 100644
--- a/testsuite/test3_bad3.tar.lz
+++ b/testsuite/test3_bad3.tar.lz
Binary files differ
diff --git a/testsuite/test3_bad4.tar.lz b/testsuite/test3_bad4.tar.lz
index 226db72..7ac6d98 100644
--- a/testsuite/test3_bad4.tar.lz
+++ b/testsuite/test3_bad4.tar.lz
Binary files differ
diff --git a/testsuite/test3a.tar.lz b/testsuite/test3_dir.tar.lz
index 8eb3f43..8eb3f43 100644
--- a/testsuite/test3a.tar.lz
+++ b/testsuite/test3_dir.tar.lz
Binary files differ
diff --git a/testsuite/test3_dot.tar.lz b/testsuite/test3_dot.tar.lz
new file mode 100644
index 0000000..3ff8960
--- /dev/null
+++ b/testsuite/test3_dot.tar.lz
Binary files differ
diff --git a/testsuite/test_bad1.txt b/testsuite/test_bad1.txt
new file mode 100644
index 0000000..f8463f4
--- /dev/null
+++ b/testsuite/test_bad1.txt
@@ -0,0 +1,307 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program \ No newline at end of file
diff --git a/testsuite/test_bad1.txt.tar b/testsuite/test_bad1.txt.tar
new file mode 100644
index 0000000..dc2140e
--- /dev/null
+++ b/testsuite/test_bad1.txt.tar
Binary files differ
diff --git a/testsuite/test_bad1.txt.tar.lz b/testsuite/test_bad1.txt.tar.lz
new file mode 100644
index 0000000..f14173d
--- /dev/null
+++ b/testsuite/test_bad1.txt.tar.lz
Binary files differ
diff --git a/testsuite/test_bad2.txt b/testsuite/test_bad2.txt
new file mode 100644
index 0000000..452408f
--- /dev/null
+++ b/testsuite/test_bad2.txt
@@ -0,0 +1,320 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. Ifodifnperived from the Progr"work based on therogrdifneneraeuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT X FR TO NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT X FR TO NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARQIS NO WARRATHERE IS NO WARRANTY
+FOR THE
+
+ This ee \ No newline at end of file
diff --git a/testsuite/test_bad2.txt.tar.lz b/testsuite/test_bad2.txt.tar.lz
new file mode 100644
index 0000000..5d30ebf
--- /dev/null
+++ b/testsuite/test_bad2.txt.tar.lz
Binary files differ
diff --git a/testsuite/tlz_in_tar1.tar b/testsuite/tlz_in_tar1.tar
new file mode 100644
index 0000000..f2dfd6c
--- /dev/null
+++ b/testsuite/tlz_in_tar1.tar
Binary files differ
diff --git a/testsuite/tlz_in_tar2.tar b/testsuite/tlz_in_tar2.tar
new file mode 100644
index 0000000..be860c6
--- /dev/null
+++ b/testsuite/tlz_in_tar2.tar
Binary files differ
diff --git a/testsuite/ug32chars.tar.lz b/testsuite/ug32chars.tar.lz
new file mode 100644
index 0000000..1397b23
--- /dev/null
+++ b/testsuite/ug32chars.tar.lz
Binary files differ