summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:27:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:27:08 +0000
commita9dff770f27dfbcef3bf768146324b03c810bfb8 (patch)
treec4040dfa674320afbe30c1f673c5c49f6a066e7f
parentReleasing debian version 1.23-6. (diff)
downloadlzip-a9dff770f27dfbcef3bf768146324b03c810bfb8.tar.xz
lzip-a9dff770f27dfbcef3bf768146324b03c810bfb8.zip
Merging upstream version 1.24~rc2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--AUTHORS2
-rw-r--r--ChangeLog22
-rw-r--r--INSTALL15
-rw-r--r--Makefile.in9
-rw-r--r--NEWS23
-rw-r--r--README52
-rw-r--r--arg_parser.cc4
-rw-r--r--arg_parser.h4
-rwxr-xr-xconfigure25
-rw-r--r--decoder.cc68
-rw-r--r--decoder.h14
-rw-r--r--doc/lzip.153
-rw-r--r--doc/lzip.info374
-rw-r--r--doc/lzip.texi387
-rw-r--r--encoder.cc2
-rw-r--r--encoder.h2
-rw-r--r--encoder_base.cc7
-rw-r--r--encoder_base.h7
-rw-r--r--fast_encoder.cc2
-rw-r--r--fast_encoder.h2
-rw-r--r--list.cc7
-rw-r--r--lzip.h56
-rw-r--r--lzip_index.cc98
-rw-r--r--lzip_index.h24
-rw-r--r--main.cc322
-rwxr-xr-xtestsuite/check.sh233
-rw-r--r--testsuite/fox6.lzbin0 -> 480 bytes
-rw-r--r--testsuite/fox6_mark.lzbin0 -> 480 bytes
28 files changed, 990 insertions, 824 deletions
diff --git a/AUTHORS b/AUTHORS
index dfc027f..e08809c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,7 +1,7 @@
Lzip was written by Antonio Diaz Diaz.
The ideas embodied in lzip are due to (at least) the following people:
-Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the
+Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the
definition of Markov chains), G.N.N. Martin (for the definition of range
encoding), Igor Pavlov (for putting all the above together in LZMA), and
Julian Seward (for bzip2's CLI).
diff --git a/ChangeLog b/ChangeLog
index 7dfae8d..da283f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-01-19 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 1.24-rc2 released.
+ * main.cc (main): Make -o preserve date/mode/owner if 1 input file.
+
+2023-12-21 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 1.24-rc1 released.
+ * New options '--empty-error' and '--marking-error'.
+ * main.cc: Reformat file diagnostics as 'PROGRAM: FILE: MESSAGE'.
+ (show_option_error): New function showing argument and option name.
+ (open_outstream): Create missing intermediate directories.
+ * lzip.h: Rename verify_* to check_*.
+ * configure, Makefile.in: New variable 'MAKEINFO'.
+ * testsuite: New test files fox6.lz, fox6_mark.lz.
+
2022-01-24 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.23 released.
@@ -62,7 +78,7 @@
* Decompression time has been reduced by 2%.
* main.cc: Continue testing if any input file is a terminal.
* main.cc: Show trailing data in both hexadecimal and ASCII.
- * encoder.cc (Matchfinder_base): Verify the size passed to new.
+ * encoder.cc (Matchfinder_base): Check the size passed to new.
* lzip_index.cc: Improve detection of bad dict and trailing data.
* lzip.h: Unify messages for bad magic, trailing data, etc.
@@ -251,7 +267,7 @@
* Lzdiff and lzgrep now accept '-h' for '--help' and
'-V' for '--version'.
* Makefile.in: Man page is now installed by default.
- * check.sh: Verify that files are opened in binary mode.
+ * check.sh: Check that files are opened in binary mode.
2009-01-24 Antonio Diaz Diaz <ant_diaz@teleline.es>
@@ -327,7 +343,7 @@
* Version 0.1 released.
-Copyright (C) 2008-2022 Antonio Diaz Diaz.
+Copyright (C) 2008-2024 Antonio Diaz Diaz.
This file is a collection of facts, and thus it is not copyrightable,
but just in case, you have unlimited permission to copy, distribute, and
diff --git a/INSTALL b/INSTALL
index e378d43..a289e1c 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,6 +1,6 @@
Requirements
------------
-You will need a C++98 compiler with suport for 'long long'.
+You will need a C++98 compiler with support for 'long long'.
(gcc 3.3.6 or newer is recommended).
I use gcc 6.1.0 and 3.3.6, but the code should compile with any standards
compliant compiler.
@@ -19,8 +19,8 @@ Procedure
or
lzip -cd lzip[version].tar.lz | tar -xf -
-This creates the directory ./lzip[version] containing the source from
-the main archive.
+This creates the directory ./lzip[version] containing the source code
+extracted from the archive.
2. Change to lzip directory and run configure.
(Try 'configure --help' for usage instructions).
@@ -39,7 +39,8 @@ the main archive.
4. Optionally, type 'make check' to run the tests that come with lzip.
5. Type 'make install' to install the program and any data files and
- documentation.
+ documentation. You need root privileges to install into a prefix owned
+ by root.
Or type 'make install-compress', which additionally compresses the
info manual and the man page after installation.
@@ -59,8 +60,8 @@ object files and executables to go and run the 'configure' script.
'configure' automatically checks for the source code in '.', in '..', and
in the directory that 'configure' is in.
-'configure' recognizes the option '--srcdir=DIR' to control where to
-look for the sources. Usually 'configure' can determine that directory
+'configure' recognizes the option '--srcdir=DIR' to control where to look
+for the source code. Usually 'configure' can determine that directory
automatically.
After running 'configure', you can run 'make' and 'make install' as
@@ -75,7 +76,7 @@ If you need to build lzip on a system lacking a 'make' program, you can use
./configure --build --check --installdir=/usr/local/bin
-Copyright (C) 2008-2022 Antonio Diaz Diaz.
+Copyright (C) 2008-2024 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute, and modify it.
diff --git a/Makefile.in b/Makefile.in
index d07ad5a..adf90e0 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -28,6 +28,10 @@ main.o : main.cc
%.o : %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
+# prevent 'make' from trying to remake source files
+$(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ;
+%.h %.cc : ;
+
$(objs) : Makefile
arg_parser.o : arg_parser.h
decoder.o : lzip.h decoder.h
@@ -38,13 +42,12 @@ list.o : lzip.h lzip_index.h
lzip_index.o : lzip.h lzip_index.h
main.o : arg_parser.h lzip.h decoder.h encoder_base.h encoder.h fast_encoder.h
-
doc : info man
info : $(VPATH)/doc/$(pkgname).info
$(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
- cd $(VPATH)/doc && makeinfo $(pkgname).texi
+ cd $(VPATH)/doc && $(MAKEINFO) $(pkgname).texi
man : $(VPATH)/doc/$(progname).1
@@ -122,6 +125,8 @@ dist : doc
$(DISTNAME)/testsuite/test.txt \
$(DISTNAME)/testsuite/fox.lz \
$(DISTNAME)/testsuite/fox_*.lz \
+ $(DISTNAME)/testsuite/fox6.lz \
+ $(DISTNAME)/testsuite/fox6_mark.lz \
$(DISTNAME)/testsuite/test.txt.lz \
$(DISTNAME)/testsuite/test_em.txt.lz
rm -f $(DISTNAME)
diff --git a/NEWS b/NEWS
index c2d6086..d29f243 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,20 @@
-Changes in version 1.23:
+Changes in version 1.24:
-Decompression time has been reduced by 5-12% depending on the file.
+The option '--empty-error', which forces exit status 2 if any empty member
+is found, has been added.
-In case of error in a numerical argument to a command line option, lzip
-now shows the name of the option and the range of valid values.
+The option '--marking-error', which forces exit status 2 if the first LZMA
+byte is non-zero in any member, has been added.
-Several descriptions have been improved in manual, '--help', and man page.
+File diagnostics have been reformatted as 'PROGRAM: FILE: MESSAGE'.
-The texinfo category of the manual has been changed from 'Data Compression'
-to 'Compression' to match that of gzip. (Reported by Alfred M. Szmidt).
+Diagnostics caused by invalid arguments to command-line options now show the
+argument and the name of the option.
+
+The option '-o, --output' now preserves dates, permissions, and ownership of
+the file, when (de)compressing exactly one file.
+
+The option '-o, --output' now creates missing intermediate directories when
+writing to a file.
+
+The variable MAKEINFO has been added to configure and Makefile.in.
diff --git a/README b/README
index 3a7ff17..2c78858 100644
--- a/README
+++ b/README
@@ -2,14 +2,15 @@ Description
Lzip is a lossless data compressor with a user interface similar to the one
of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov
-chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity
-checking to maximize interoperability and optimize safety. Lzip can compress
-about as fast as gzip (lzip -0) or compress most files more than bzip2
-(lzip -9). Decompression speed is intermediate between gzip and bzip2.
-Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip
-has been designed, written, and tested with great care to replace gzip and
-bzip2 as the standard general-purpose compressed format for unix-like
-systems.
+chain-Algorithm' (LZMA) stream format to maximize interoperability. The
+maximum dictionary size is 512 MiB so that any lzip file can be decompressed
+on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
+checking. Lzip can compress about as fast as gzip (lzip -0) or compress most
+files more than bzip2 (lzip -9). Decompression speed is intermediate between
+gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
+perspective. Lzip has been designed, written, and tested with great care to
+replace gzip and bzip2 as the standard general-purpose compressed format for
+Unix-like systems.
For compressing/decompressing large files on multiprocessor machines plzip
can be much faster than lzip at the cost of a slightly reduced compression
@@ -47,9 +48,9 @@ Lzip uses the same well-defined exit status values used by bzip2, which
makes it safer than compressors returning ambiguous warning values (like
gzip) when it is used as a back end for other programs like tar or zutils.
-Lzip will automatically use for each file the largest dictionary size that
-does not exceed neither the file size nor the limit given. Keep in mind that
-the decompression memory requirement is affected at compression time by the
+Lzip automatically uses for each file the largest dictionary size that does
+not exceed neither the file size nor the limit given. Keep in mind that the
+decompression memory requirement is affected at compression time by the
choice of dictionary size limit.
The amount of memory required for compression is about 1 or 2 times the
@@ -69,20 +70,20 @@ filename.tlz becomes filename.tar
anyothername becomes anyothername.out
(De)compressing a file is much like copying or moving it. Therefore lzip
-preserves the access and modification dates, permissions, and, when
-possible, ownership of the file just as 'cp -p' does. (If the user ID or
-the group ID can't be duplicated, the file permission bits S_ISUID and
-S_ISGID are cleared).
+preserves the access and modification dates, permissions, and, if you have
+appropriate privileges, ownership of the file just as 'cp -p' does. (If the
+user ID or the group ID can't be duplicated, the file permission bits
+S_ISUID and S_ISGID are cleared).
Lzip is able to read from some types of non-regular files if either the
option '-c' or the option '-o' is specified.
If no file names are specified, lzip compresses (or decompresses) from
-standard input to standard output. Lzip will refuse to read compressed data
+standard input to standard output. Lzip refuses to read compressed data
from a terminal or write compressed data to a terminal, as this would be
entirely incomprehensible and might leave the terminal in an abnormal state.
-Lzip will correctly decompress a file which is the concatenation of two or
+Lzip correctly decompresses a file which is the concatenation of two or
more compressed files. The result is the concatenation of the corresponding
decompressed files. Integrity testing of concatenated compressed files is
also supported.
@@ -109,13 +110,13 @@ Lzip currently implements two variants of the LZMA algorithm: fast
(used by option '-0') and normal (used by all other compression levels).
The high compression of LZMA comes from combining two basic, well-proven
-compression ideas: sliding dictionaries (LZ77/78) and markov models (the
-thing used by every compression algorithm that uses a range encoder or
-similar order-0 entropy coder as its last stage) with segregation of
-contexts according to what the bits are used for.
+compression ideas: sliding dictionaries (LZ77) and markov models (the thing
+used by every compression algorithm that uses a range encoder or similar
+order-0 entropy coder as its last stage) with segregation of contexts
+according to what the bits are used for.
The ideas embodied in lzip are due to (at least) the following people:
-Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the
+Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the
definition of Markov chains), G.N.N. Martin (for the definition of range
encoding), Igor Pavlov (for putting all the above together in LZMA), and
Julian Seward (for bzip2's CLI).
@@ -125,11 +126,10 @@ been compressed. Decompressed is used to refer to data which have undergone
the process of decompression.
-Copyright (C) 2008-2022 Antonio Diaz Diaz.
+Copyright (C) 2008-2024 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute, and modify it.
-The file Makefile.in is a data file used by configure to produce the
-Makefile. It has the same copyright owner and permissions that configure
-itself.
+The file Makefile.in is a data file used by configure to produce the Makefile.
+It has the same copyright owner and permissions that configure itself.
diff --git a/arg_parser.cc b/arg_parser.cc
index 59998ac..0c04d8e 100644
--- a/arg_parser.cc
+++ b/arg_parser.cc
@@ -1,5 +1,5 @@
-/* Arg_parser - POSIX/GNU command line argument parser. (C++ version)
- Copyright (C) 2006-2022 Antonio Diaz Diaz.
+/* Arg_parser - POSIX/GNU command-line argument parser. (C++ version)
+ Copyright (C) 2006-2024 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
diff --git a/arg_parser.h b/arg_parser.h
index e854838..1eeec9a 100644
--- a/arg_parser.h
+++ b/arg_parser.h
@@ -1,5 +1,5 @@
-/* Arg_parser - POSIX/GNU command line argument parser. (C++ version)
- Copyright (C) 2006-2022 Antonio Diaz Diaz.
+/* Arg_parser - POSIX/GNU command-line argument parser. (C++ version)
+ Copyright (C) 2006-2024 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
diff --git a/configure b/configure
index 0ea474c..f0783cb 100755
--- a/configure
+++ b/configure
@@ -1,12 +1,12 @@
#! /bin/sh
# configure script for Lzip - LZMA lossless data compressor
-# Copyright (C) 2008-2022 Antonio Diaz Diaz.
+# Copyright (C) 2008-2024 Antonio Diaz Diaz.
#
# This configure script is free software: you have unlimited permission
# to copy, distribute, and modify it.
pkgname=lzip
-pkgversion=1.23
+pkgversion=1.24-rc2
progname=lzip
srctrigger=doc/${pkgname}.texi
@@ -27,6 +27,7 @@ CXX=g++
CPPFLAGS=
CXXFLAGS='-Wall -W -O2'
LDFLAGS=
+MAKEINFO=makeinfo
# checking whether we are using GNU C++.
/bin/sh -c "${CXX} --version" > /dev/null 2>&1 || { CXX=c++ ; CXXFLAGS=-O2 ; }
@@ -60,7 +61,7 @@ while [ $# != 0 ] ; do
echo "Options and variables: [defaults in brackets]"
echo " -h, --help display this help and exit"
echo " -V, --version output version information and exit"
- echo " --srcdir=DIR find the sources in DIR [. or ..]"
+ echo " --srcdir=DIR find the source code in DIR [. or ..]"
echo " --prefix=DIR install into DIR [${prefix}]"
echo " --exec-prefix=DIR base directory for arch-dependent files [${exec_prefix}]"
echo " --bindir=DIR user executables directory [${bindir}]"
@@ -71,10 +72,11 @@ while [ $# != 0 ] ; do
echo " --check check without using 'make', implies --build"
echo " --installdir=BINDIR install without using 'make', implies --build"
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 " 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 " LDFLAGS=OPTIONS command-line options for the linker [${LDFLAGS}]"
+ echo " MAKEINFO=NAME makeinfo program to use [${MAKEINFO}]"
echo
exit 0 ;;
--version | -V)
@@ -106,6 +108,7 @@ while [ $# != 0 ] ; do
CXXFLAGS=*) CXXFLAGS=${optarg} ;;
CXXFLAGS+=*) CXXFLAGS="${CXXFLAGS} ${optarg}" ;;
LDFLAGS=*) LDFLAGS=${optarg} ;;
+ MAKEINFO=*) MAKEINFO=${optarg} ;;
--*)
echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;;
@@ -125,7 +128,7 @@ while [ $# != 0 ] ; do
fi
done
-# Find the source files, if location was not specified.
+# Find the source code, if location was not specified.
srcdirtext=
if [ -z "${srcdir}" ] ; then
srcdirtext="or . or .." ; srcdir=.
@@ -137,7 +140,7 @@ if [ -z "${srcdir}" ] ; then
fi
if [ ! -r "${srcdir}/${srctrigger}" ] ; then
- echo "configure: Can't find sources in ${srcdir} ${srcdirtext}" 1>&2
+ echo "configure: Can't find source code in ${srcdir} ${srcdirtext}" 1>&2
echo "configure: (At least ${srctrigger} is missing)." 1>&2
exit 1
fi
@@ -180,7 +183,7 @@ if [ -z "${no_create}" ] ; then
# This script is free software: you have unlimited permission
# to copy, distribute, and modify it.
-exec /bin/sh $0 ${args} --no-create
+exec /bin/sh "$0" ${args} --no-create
EOF
chmod +x config.status
fi
@@ -197,10 +200,11 @@ echo "CXX = ${CXX}"
echo "CPPFLAGS = ${CPPFLAGS}"
echo "CXXFLAGS = ${CXXFLAGS}"
echo "LDFLAGS = ${LDFLAGS}"
+echo "MAKEINFO = ${MAKEINFO}"
rm -f Makefile
cat > Makefile << EOF
# Makefile for Lzip - LZMA lossless data compressor
-# Copyright (C) 2008-2022 Antonio Diaz Diaz.
+# Copyright (C) 2008-2024 Antonio Diaz Diaz.
# This file was generated automatically by configure. Don't edit.
#
# This Makefile is free software: you have unlimited permission
@@ -220,6 +224,7 @@ CXX = ${CXX}
CPPFLAGS = ${CPPFLAGS}
CXXFLAGS = ${CXXFLAGS}
LDFLAGS = ${LDFLAGS}
+MAKEINFO = ${MAKEINFO}
EOF
cat "${srcdir}/Makefile.in" >> Makefile
diff --git a/decoder.cc b/decoder.cc
index 4cd2819..16aa016 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -98,24 +98,21 @@ void LZ_decoder::flush_data()
}
-bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
+int LZ_decoder::check_trailer( const Pretty_print & pp,
+ const bool ignore_empty ) const
{
Lzip_trailer trailer;
- int size = rdec.read_data( trailer.data, Lzip_trailer::size );
- const unsigned long long data_size = data_position();
- const unsigned long long member_size = rdec.member_position();
+ int size = rdec.read_data( trailer.data, trailer.size );
bool error = false;
- if( size < Lzip_trailer::size )
+ if( size < trailer.size )
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "Trailer truncated at trailer position %d;"
- " some checks may fail.\n", size );
- }
- while( size < Lzip_trailer::size ) trailer.data[size++] = 0;
+ { pp();
+ std::fprintf( stderr, "Trailer truncated at trailer position %d;"
+ " some checks may fail.\n", size ); }
+ while( size < trailer.size ) trailer.data[size++] = 0;
}
const unsigned td_crc = trailer.data_crc();
@@ -123,35 +120,32 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "CRC mismatch; stored %08X, computed %08X\n",
- td_crc, crc() );
- }
+ { pp();
+ std::fprintf( stderr, "CRC mismatch; stored %08X, computed %08X\n",
+ td_crc, crc() ); }
}
+ const unsigned long long data_size = data_position();
const unsigned long long td_size = trailer.data_size();
if( td_size != data_size )
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "Data size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
- td_size, td_size, data_size, data_size );
- }
+ { pp();
+ std::fprintf( stderr, "Data size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
+ td_size, td_size, data_size, data_size ); }
}
+ const unsigned long long member_size = rdec.member_position();
const unsigned long long tm_size = trailer.member_size();
if( tm_size != member_size )
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "Member size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
- tm_size, tm_size, member_size, member_size );
- }
+ { pp();
+ std::fprintf( stderr, "Member size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
+ tm_size, tm_size, member_size, member_size ); }
}
- if( error ) return false;
+ if( error ) return 3;
+ if( !ignore_empty && data_size == 0 ) return 5;
if( verbosity >= 2 )
{
if( verbosity >= 4 ) show_header( dictionary_size );
@@ -166,13 +160,15 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
if( verbosity >= 3 )
std::fprintf( stderr, "%9llu out, %8llu in. ", data_size, member_size );
}
- return true;
+ return 0;
}
/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF,
- 3 = trailer error, 4 = unknown marker found. */
-int LZ_decoder::decode_member( const Pretty_print & pp )
+ 3 = trailer error, 4 = unknown marker found,
+ 5 = empty member found, 6 = marked member found. */
+int LZ_decoder::decode_member( const Cl_options & cl_opts,
+ const Pretty_print & pp )
{
Bit_model bm_literal[1<<literal_context_bits][0x300];
Bit_model bm_match[State::states][pos_states];
@@ -192,7 +188,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
unsigned rep3 = 0;
State state;
- rdec.load();
+ if( !rdec.load( cl_opts.ignore_marking ) ) return 6;
while( !rdec.finished() )
{
const int pos_state = data_position() & pos_state_mask;
@@ -256,13 +252,9 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
rdec.normalize();
flush_data();
if( len == min_match_len ) // End Of Stream marker
- {
- if( verify_trailer( pp ) ) return 0; else return 3;
- }
+ return check_trailer( pp, cl_opts.ignore_empty );
if( len == min_match_len + 1 ) // Sync Flush marker
- {
- rdec.load(); continue;
- }
+ { rdec.load(); continue; }
if( verbosity >= 0 )
{
pp();
diff --git a/decoder.h b/decoder.h
index 29fdef6..cf10f3d 100644
--- a/decoder.h
+++ b/decoder.h
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -75,12 +75,14 @@ public:
return sz;
}
- void load()
+ bool load( const bool ignore_marking = true )
{
code = 0;
- for( int i = 0; i < 5; ++i ) code = ( code << 8 ) | get_byte();
range = 0xFFFFFFFFU;
- code &= range; // make sure that first byte is discarded
+ // check and discard first byte of the LZMA stream
+ if( get_byte() != 0 && !ignore_marking ) return false;
+ for( int i = 0; i < 4; ++i ) code = ( code << 8 ) | get_byte();
+ return true;
}
void normalize()
@@ -268,7 +270,7 @@ class LZ_decoder
bool pos_wrapped;
void flush_data();
- bool verify_trailer( const Pretty_print & pp ) const;
+ int check_trailer( const Pretty_print & pp, const bool ignore_empty ) const;
uint8_t peek_prev() const
{ return buffer[((pos > 0) ? pos : dictionary_size)-1]; }
@@ -340,5 +342,5 @@ public:
unsigned crc() const { return crc_ ^ 0xFFFFFFFFU; }
unsigned long long data_position() const { return partial_data_pos + pos; }
- int decode_member( const Pretty_print & pp );
+ int decode_member( const Cl_options & cl_opts, const Pretty_print & pp );
};
diff --git a/doc/lzip.1 b/doc/lzip.1
index 720c7a0..824a113 100644
--- a/doc/lzip.1
+++ b/doc/lzip.1
@@ -1,5 +1,5 @@
-.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.16.
-.TH LZIP "1" "January 2022" "lzip 1.23" "User Commands"
+.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
+.TH LZIP "1" "January 2024" "lzip 1.24-rc2" "User Commands"
.SH NAME
lzip \- reduces the size of files
.SH SYNOPSIS
@@ -8,14 +8,15 @@ lzip \- reduces the size of files
.SH DESCRIPTION
Lzip is a lossless data compressor with a user interface similar to the one
of gzip or bzip2. Lzip uses a simplified form of the 'Lempel\-Ziv\-Markov
-chain\-Algorithm' (LZMA) stream format and provides a 3 factor integrity
-checking to maximize interoperability and optimize safety. Lzip can compress
-about as fast as gzip (lzip \fB\-0\fR) or compress most files more than bzip2
-(lzip \fB\-9\fR). Decompression speed is intermediate between gzip and bzip2.
-Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip
-has been designed, written, and tested with great care to replace gzip and
-bzip2 as the standard general\-purpose compressed format for unix\-like
-systems.
+chain\-Algorithm' (LZMA) stream format to maximize interoperability. The
+maximum dictionary size is 512 MiB so that any lzip file can be decompressed
+on 32\-bit machines. Lzip provides accurate and robust 3\-factor integrity
+checking. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or compress most
+files more than bzip2 (lzip \fB\-9\fR). Decompression speed is intermediate between
+gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
+perspective. Lzip has been designed, written, and tested with great care to
+replace gzip and bzip2 as the standard general\-purpose compressed format for
+Unix\-like systems.
.SH OPTIONS
.TP
\fB\-h\fR, \fB\-\-help\fR
@@ -34,7 +35,7 @@ set member size limit in bytes
write to standard output, keep input files
.TP
\fB\-d\fR, \fB\-\-decompress\fR
-decompress
+decompress, test compressed file integrity
.TP
\fB\-f\fR, \fB\-\-force\fR
overwrite existing output files
@@ -78,6 +79,12 @@ alias for \fB\-0\fR
\fB\-\-best\fR
alias for \fB\-9\fR
.TP
+\fB\-\-empty\-error\fR
+exit with error status if empty member in file
+.TP
+\fB\-\-marking\-error\fR
+exit with error status if 1st LZMA byte not 0
+.TP
\fB\-\-loose\-trailing\fR
allow trailing data seeming corrupt header
.PP
@@ -85,24 +92,24 @@ If no file names are given, or if a file is '\-', lzip compresses or
decompresses from standard input to standard output.
Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,
Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...
-Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12
-to 2^29 bytes.
+Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12 to
+2^29 bytes.
.PP
-The bidimensional parameter space of LZMA can't be mapped to a linear
-scale optimal for all files. If your files are large, very repetitive,
-etc, you may need to use the options \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR
-directly to achieve optimal performance.
+The bidimensional parameter space of LZMA can't be mapped to a linear scale
+optimal for all files. If your files are large, very repetitive, etc, you
+may need to use the options \fB\-\-dictionary\-size\fR and \fB\-\-match\-length\fR directly
+to achieve optimal performance.
.PP
To extract all the files from archive 'foo.tar.lz', use the commands
\&'tar \fB\-xf\fR foo.tar.lz' or 'lzip \fB\-cd\fR foo.tar.lz | tar \fB\-xf\fR \-'.
.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
-invalid input file, 3 for an internal consistency error (e.g., bug) which
-caused lzip to panic.
+Exit status: 0 for a normal exit, 1 for environmental problems
+(file not found, invalid command\-line options, I/O errors, etc), 2 to
+indicate a corrupt or invalid input file, 3 for an internal consistency
+error (e.g., bug) which caused lzip to panic.
.PP
The ideas embodied in lzip are due to (at least) the following people:
-Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the
+Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the
definition of Markov chains), G.N.N. Martin (for the definition of range
encoding), Igor Pavlov (for putting all the above together in LZMA), and
Julian Seward (for bzip2's CLI).
@@ -111,7 +118,7 @@ Report bugs to lzip\-bug@nongnu.org
.br
Lzip home page: http://www.nongnu.org/lzip/lzip.html
.SH COPYRIGHT
-Copyright \(co 2022 Antonio Diaz Diaz.
+Copyright \(co 2024 Antonio Diaz Diaz.
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/lzip.info b/doc/lzip.info
index 7c6d812..5c397d3 100644
--- a/doc/lzip.info
+++ b/doc/lzip.info
@@ -11,13 +11,13 @@ File: lzip.info, Node: Top, Next: Introduction, Up: (dir)
Lzip Manual
***********
-This manual is for Lzip (version 1.23, 24 January 2022).
+This manual is for Lzip (version 1.24-rc2, 19 January 2024).
* Menu:
* Introduction:: Purpose and features of lzip
* Output:: Meaning of lzip's output
-* Invoking lzip:: Command line interface
+* Invoking lzip:: Command-line interface
* Quality assurance:: Design, development, and testing of lzip
* Algorithm:: How lzip compresses the data
* File format:: Detailed format of the compressed file
@@ -29,7 +29,7 @@ This manual is for Lzip (version 1.23, 24 January 2022).
* Concept index:: Index of concepts
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
This manual is free documentation: you have unlimited permission to copy,
distribute, and modify it.
@@ -42,14 +42,15 @@ File: lzip.info, Node: Introduction, Next: Output, Prev: Top, Up: Top
Lzip is a lossless data compressor with a user interface similar to the one
of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov
-chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity
-checking to maximize interoperability and optimize safety. Lzip can compress
-about as fast as gzip (lzip -0) or compress most files more than bzip2
-(lzip -9). Decompression speed is intermediate between gzip and bzip2. Lzip
-is better than gzip and bzip2 from a data recovery perspective. Lzip has
-been designed, written, and tested with great care to replace gzip and
-bzip2 as the standard general-purpose compressed format for unix-like
-systems.
+chain-Algorithm' (LZMA) stream format to maximize interoperability. The
+maximum dictionary size is 512 MiB so that any lzip file can be decompressed
+on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
+checking. Lzip can compress about as fast as gzip (lzip -0) or compress most
+files more than bzip2 (lzip -9). Decompression speed is intermediate between
+gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
+perspective. Lzip has been designed, written, and tested with great care to
+replace gzip and bzip2 as the standard general-purpose compressed format for
+Unix-like systems.
For compressing/decompressing large files on multiprocessor machines
plzip can be much faster than lzip at the cost of a slightly reduced
@@ -87,22 +88,22 @@ byte near the beginning is a thing of the past.
The member trailer stores the 32-bit CRC of the original data, the size
of the original data, and the size of the member. These values, together
-with the "End Of Stream" marker, provide a 3 factor integrity checking
-which guarantees that the decompressed version of the data is identical to
-the original. This guards against corruption of the compressed data, and
-against undetected bugs in lzip (hopefully very unlikely). The chances of
-data corruption going undetected are microscopic. Be aware, though, that
-the check occurs upon decompression, so it can only tell you that something
-is wrong. It can't help you recover the original uncompressed data.
+with the "End Of Stream" marker, provide a 3-factor integrity checking which
+guarantees that the decompressed version of the data is identical to the
+original. This guards against corruption of the compressed data, and against
+undetected bugs in lzip (hopefully very unlikely). The chances of data
+corruption going undetected are microscopic. Be aware, though, that the
+check occurs upon decompression, so it can only tell you that something is
+wrong. It can't help you recover the original uncompressed data.
Lzip uses the same well-defined exit status values used by bzip2, which
makes it safer than compressors returning ambiguous warning values (like
gzip) when it is used as a back end for other programs like tar or zutils.
- Lzip will automatically use for each file the largest dictionary size
-that does not exceed neither the file size nor the limit given. Keep in
-mind that the decompression memory requirement is affected at compression
-time by the choice of dictionary size limit.
+ Lzip automatically uses for each file the largest dictionary size that
+does not exceed neither the file size nor the limit given. Keep in mind
+that the decompression memory requirement is affected at compression time
+by the choice of dictionary size limit.
The amount of memory required for compression is about 1 or 2 times the
dictionary size limit (1 if input file size is less than dictionary size
@@ -121,22 +122,22 @@ filename.tlz becomes filename.tar
anyothername becomes anyothername.out
(De)compressing a file is much like copying or moving it. Therefore lzip
-preserves the access and modification dates, permissions, and, when
-possible, ownership of the file just as 'cp -p' does. (If the user ID or
-the group ID can't be duplicated, the file permission bits S_ISUID and
-S_ISGID are cleared).
+preserves the access and modification dates, permissions, and, if you have
+appropriate privileges, ownership of the file just as 'cp -p' does. (If the
+user ID or the group ID can't be duplicated, the file permission bits
+S_ISUID and S_ISGID are cleared).
Lzip is able to read from some types of non-regular files if either the
option '-c' or the option '-o' is specified.
- Lzip will refuse to read compressed data from a terminal or write
-compressed data to a terminal, as this would be entirely incomprehensible
-and might leave the terminal in an abnormal state.
+ Lzip refuses to read compressed data from a terminal or write compressed
+data to a terminal, as this would be entirely incomprehensible and might
+leave the terminal in an abnormal state.
- Lzip will correctly decompress a file which is the concatenation of two
-or more compressed files. The result is the concatenation of the
-corresponding decompressed files. Integrity testing of concatenated
-compressed files is also supported.
+ Lzip correctly decompresses a file which is the concatenation of two or
+more compressed files. The result is the concatenation of the corresponding
+decompressed files. Integrity testing of concatenated compressed files is
+also supported.
Lzip can produce multimember files, and lziprecover can safely recover
the undamaged members in case of file damage. Lzip can also split the
@@ -208,7 +209,8 @@ The format for running lzip is:
If no file names are specified, lzip compresses (or decompresses) from
standard input to standard output. A hyphen '-' used as a FILE argument
means standard input. It can be mixed with other FILES and is read just
-once, the first time it appears in the command line.
+once, the first time it appears in the command line. Remember to prepend
+'./' to any file name beginning with a hyphen, or use '--'.
lzip supports the following options: *Note Argument syntax:
(arg_parser)Argument syntax.
@@ -248,13 +250,14 @@ once, the first time it appears in the command line.
'-d'
'--decompress'
- Decompress the files specified. If a file does not exist, can't be
- opened, or the destination file already exists and '--force' has not
- been specified, lzip continues decompressing the rest of the files and
- exits with error status 1. If a file fails to decompress, or is a
- terminal, lzip exits immediately with error status 2 without
- decompressing the rest of the files. A terminal is considered an
- uncompressed file, and therefore invalid.
+ Decompress the files specified. The integrity of the files specified is
+ checked. If a file does not exist, can't be opened, or the destination
+ file already exists and '--force' has not been specified, lzip
+ continues decompressing the rest of the files and exits with error
+ status 1. If a file fails to decompress, or is a terminal, lzip exits
+ immediately with error status 2 without decompressing the rest of the
+ files. A terminal is considered an uncompressed file, and therefore
+ invalid.
'-f'
'--force'
@@ -281,26 +284,27 @@ once, the first time it appears in the command line.
printed.
If any file is damaged, does not exist, can't be opened, or is not
- regular, the final exit status will be > 0. '-lq' can be used to verify
+ regular, the final exit status is > 0. '-lq' can be used to check
quickly (without decompressing) the structural integrity of the files
- specified. (Use '--test' to verify the data integrity). '-alq'
- additionally verifies that none of the files specified contain
- trailing data.
+ specified. (Use '--test' to check the data integrity). '-alq'
+ additionally checks that none of the files specified contain trailing
+ data.
'-m BYTES'
'--match-length=BYTES'
When compressing, set the match length limit in bytes. After a match
this long is found, the search is finished. Valid values range from 5
- to 273. Larger values usually give better compression ratios but longer
- compression times.
+ to 273. Larger values usually give better compression ratios but
+ longer compression times.
'-o FILE'
'--output=FILE'
- If '-c' has not been also specified, write the (de)compressed output to
- FILE; keep input files unchanged. If compressing several files, each
- file is compressed independently. (The output consists of a sequence of
- independently compressed members). This option (or '-c') is needed when
- reading from a named pipe (fifo) or from a device. '-o -' is
+ If '-c' has not been also specified, write the (de)compressed output
+ to FILE, automatically creating any missing parent directories; keep
+ input files unchanged. If compressing several files, each file is
+ compressed independently. (The output consists of a sequence of
+ independently compressed members). This option (or '-c') is needed
+ when reading from a named pipe (fifo) or from a device. '-o -' is
equivalent to '-c'. '-o' has no effect when testing or listing.
In order to keep backward compatibility with lzip versions prior to
@@ -321,14 +325,14 @@ once, the first time it appears in the command line.
'-s BYTES'
'--dictionary-size=BYTES'
- When compressing, set the dictionary size limit in bytes. Lzip will use
- for each file the largest dictionary size that does not exceed neither
- the file size nor this limit. Valid values range from 4 KiB to
- 512 MiB. Values 12 to 29 are interpreted as powers of two, meaning
- 2^12 to 2^29 bytes. Dictionary sizes are quantized so that they can be
- coded in just one byte (*note coded-dict-size::). If the size specified
- does not match one of the valid sizes, it will be rounded upwards by
- adding up to (BYTES / 8) to it.
+ When compressing, set the dictionary size limit in bytes. Lzip uses for
+ each file the largest dictionary size that does not exceed neither the
+ file size nor this limit. Valid values range from 4 KiB to 512 MiB.
+ Values 12 to 29 are interpreted as powers of two, meaning 2^12 to 2^29
+ bytes. Dictionary sizes are quantized so that they can be coded in
+ just one byte (*note coded-dict-size::). If the size specified does
+ not match one of the valid sizes, it is rounded upwards by adding up
+ to (BYTES / 8) to it.
For maximum compression you should use a dictionary size limit as large
as possible, but keep in mind that the decompression memory requirement
@@ -350,8 +354,8 @@ once, the first time it appears in the command line.
really performs a trial decompression and throws away the result. Use
it together with '-v' to see information about the files. If a file
fails the test, does not exist, can't be opened, or is a terminal, lzip
- continues checking the rest of the files. A final diagnostic is shown
- at verbosity level 1 or higher if any file fails the test when testing
+ continues testing the rest of the files. A final diagnostic is shown at
+ verbosity level 1 or higher if any file fails the test when testing
multiple files.
'-v'
@@ -398,6 +402,16 @@ once, the first time it appears in the command line.
'--best'
Aliases for GNU gzip compatibility.
+'--empty-error'
+ Exit with error status 2 if any empty member is found in the input
+ files.
+
+'--marking-error'
+ Exit with error status 2 if the first LZMA byte is non-zero in any
+ member of the input files. This may be caused by data corruption or by
+ deliberate insertion of tracking information in the file. Use
+ 'lziprecover --clear-marking' to clear any such non-zero bytes.
+
'--loose-trailing'
When decompressing, testing, or listing, allow trailing data whose
first bytes are so similar to the magic bytes of a lzip header that
@@ -406,26 +420,29 @@ once, the first time it appears in the command line.
corrupt header.
- Numbers given as arguments to options may be followed by a multiplier
-and an optional 'B' for "byte".
+ Numbers given as arguments to options may be expressed in decimal,
+hexadecimal, or octal (using the same syntax as integer constants in C++),
+and may be followed by a multiplier and an optional 'B' for "byte".
Table of SI and binary prefixes (unit multipliers):
-Prefix Value | Prefix Value
-k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024)
-M megabyte (10^6) | Mi mebibyte (2^20)
-G gigabyte (10^9) | Gi gibibyte (2^30)
-T terabyte (10^12) | Ti tebibyte (2^40)
-P petabyte (10^15) | Pi pebibyte (2^50)
-E exabyte (10^18) | Ei exbibyte (2^60)
-Z zettabyte (10^21) | Zi zebibyte (2^70)
-Y yottabyte (10^24) | Yi yobibyte (2^80)
+Prefix Value | Prefix Value
+k kilobyte (10^3 = 1000) | Ki kibibyte (2^10 = 1024)
+M megabyte (10^6) | Mi mebibyte (2^20)
+G gigabyte (10^9) | Gi gibibyte (2^30)
+T terabyte (10^12) | Ti tebibyte (2^40)
+P petabyte (10^15) | Pi pebibyte (2^50)
+E exabyte (10^18) | Ei exbibyte (2^60)
+Z zettabyte (10^21) | Zi zebibyte (2^70)
+Y yottabyte (10^24) | Yi yobibyte (2^80)
+R ronnabyte (10^27) | Ri robibyte (2^90)
+Q quettabyte (10^30) | Qi quebibyte (2^100)
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 invalid
-input file, 3 for an internal consistency error (e.g., bug) which caused
-lzip to panic.
+found, invalid command-line options, I/O errors, etc), 2 to indicate a
+corrupt or invalid input file, 3 for an internal consistency error (e.g.,
+bug) which caused lzip to panic.

File: lzip.info, Node: Quality assurance, Next: Algorithm, Prev: Invoking lzip, Up: Top
@@ -439,17 +456,12 @@ make it so complicated that there are no obvious deficiencies. The first
method is far more difficult.
-- C.A.R. Hoare
- Lzip is developed by volunteers who lack the resources required for
-extensive testing in all circumstances. It is up to you to test lzip before
-using it in mission-critical applications. However, a compressor like lzip
-is not a toy, and maintaining it is not a hobby. Many people's data depend
-on it. Therefore the lzip file format has been reviewed carefully and is
-believed to be free from negligent design errors.
-
Lzip has been designed, written, and tested with great care to replace
gzip and bzip2 as the standard general-purpose compressed format for
-unix-like systems. This chapter describes the lessons learned from these
-previous formats, and their application to the design of lzip.
+Unix-like systems. This chapter describes the lessons learned from these
+previous formats, and their application to the design of lzip. The lzip
+format specification has been reviewed carefully and is believed to be free
+from design errors.
4.1 Format design
@@ -532,10 +544,10 @@ extraction of the decompressed data.
Using an optional CRC for the header is not only a bad idea, it is an
error; it circumvents the Hamming distance (HD) of the CRC and may
prevent the extraction of perfectly good data. For example, if the CRC
- is used and the bit enabling it is reset by a bit flip, the header
- will appear to be intact (in spite of being corrupt) while the
- compressed blocks will appear to be totally unrecoverable (in spite of
- being intact). Very misleading indeed.
+ is used and the bit enabling it is reset by a bit flip, then the
+ header seems to be intact (in spite of being corrupt) while the
+ compressed blocks seem to be totally unrecoverable (in spite of being
+ intact). Very misleading indeed.
'Metadata'
The gzip format stores some metadata, like the modification time of the
@@ -550,8 +562,8 @@ extraction of the decompressed data.
'64-bit size field'
Probably the most frequently reported shortcoming of the gzip format
is that it only stores the least significant 32 bits of the
- uncompressed size. The size of any file larger than 4 GiB gets
- truncated.
+ uncompressed size. The size of any file larger or equal than 4 GiB
+ gets truncated.
Bzip2 does not store the uncompressed size of the file.
@@ -575,8 +587,12 @@ extraction of the decompressed data.
4.2 Quality of implementation
=============================
+Our civilization depends critically on software; it had better be quality
+software.
+-- Bjarne Stroustrup
+
'Accurate and robust error detection'
- The lzip format provides 3 factor integrity checking, and the
+ The lzip format provides 3-factor integrity checking, and the
decompressors report mismatches in each factor separately. This method
detects most false positives for corruption. If just one byte in one
factor fails but the other two factors match the data, it probably
@@ -585,15 +601,15 @@ extraction of the decompressed data.
trailer.
'Multiple implementations'
- Just like the lzip format provides 3 factor protection against
+ Just like the lzip format provides 3-factor protection against
undetected data corruption, the development methodology of the lzip
- family of compressors provides 3 factor protection against undetected
+ family of compressors provides 3-factor protection against undetected
programming errors.
Three related but independent compressor implementations, lzip, clzip,
and minilzip/lzlib, are developed concurrently. Every stable release
- of any of them is tested to verify that it produces identical output
- to the other two. This guarantees that all three implement the same
+ of any of them is tested to check that it produces identical output to
+ the other two. This guarantees that all three implement the same
algorithm, and makes it unlikely that any of them may contain serious
undiscovered errors. In fact, no errors have been discovered in lzip
since 2009.
@@ -637,10 +653,10 @@ using the LZMA coding scheme.
by option '-0') and normal (used by all other compression levels).
The high compression of LZMA comes from combining two basic, well-proven
-compression ideas: sliding dictionaries (LZ77/78) and markov models (the
-thing used by every compression algorithm that uses a range encoder or
-similar order-0 entropy coder as its last stage) with segregation of
-contexts according to what the bits are used for.
+compression ideas: sliding dictionaries (LZ77) and markov models (the thing
+used by every compression algorithm that uses a range encoder or similar
+order-0 entropy coder as its last stage) with segregation of contexts
+according to what the bits are used for.
Lzip is a two stage compressor. The first stage is a Lempel-Ziv coder,
which reduces redundancy by translating chunks of data to their
@@ -685,7 +701,7 @@ get longer with higher compression levels because dictionary size increases
(and compression speed decreases) with compression level.
The ideas embodied in lzip are due to (at least) the following people:
-Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the
+Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the
definition of Markov chains), G.N.N. Martin (for the definition of range
encoding), Igor Pavlov (for putting all the above together in LZMA), and
Julian Seward (for bzip2's CLI).
@@ -716,7 +732,7 @@ when there is no longer anything to take away.
represents a variable number of bytes.
- A lzip file consists of a series of independent "members" (compressed
+ A lzip file consists of one or more independent "members" (compressed
data sets). The members simply appear one after another in the file, with no
additional information before, between, or after them. Each member can
encode in compressed form up to 16 EiB - 1 byte of uncompressed data. The
@@ -760,10 +776,10 @@ size of a multimember file is unlimited.
'Member size (8 bytes)'
Total size of the member, including header and trailer. This field acts
- as a distributed index, allows the verification of stream integrity,
- and facilitates the safe recovery of undamaged members from
- multimember files. Member size should be limited to 2 PiB to prevent
- the data size field from overflowing.
+ as a distributed index, improves the checking of stream integrity, and
+ facilitates the safe recovery of undamaged members from multimember
+ files. Lzip limits the member size to 2 PiB to prevent the data size
+ field from overflowing.

@@ -783,12 +799,12 @@ in the code.
Lzip finishes the LZMA stream with an "End Of Stream" (EOS) marker (the
distance-length pair 0xFFFFFFFFU, 2), which in conjunction with the 'member
-size' field in the member trailer allows the verification of stream
-integrity. The EOS marker is the only marker allowed in lzip files. The
-LZMA stream in lzip files always has these two features (default properties
-and EOS marker) and is referred to in this document as LZMA-302eos. This
-simplified form of the LZMA stream format has been chosen to maximize
-interoperability and safety.
+size' field in the member trailer allows the checking of stream integrity.
+The EOS marker is the only LZMA marker allowed in lzip files. The LZMA
+stream in lzip files always has these two features (default properties and
+EOS marker) and is referred to in this document as LZMA-302eos. This
+simplified and marker-terminated form of the LZMA stream format has been
+chosen to maximize interoperability and safety.
The second stage of LZMA is a range encoder that uses a different
probability model for each type of symbol: distances, lengths, literal
@@ -806,9 +822,9 @@ a real decompressor seems the only appropriate reference to use.
What follows is a description of the decoding algorithm for LZMA-302eos
streams using as reference the source code of "lzd", an educational
-decompressor for lzip files which can be downloaded from the lzip download
-directory. Lzd is written in C++11 and its source code is included in
-appendix A. *Note Reference source code::.
+decompressor for lzip files, included in appendix A. *Note Reference source
+code::. Lzd is written in C++11 and can be downloaded from the lzip download
+directory.
7.1 What is coded
@@ -873,10 +889,10 @@ the distance is >= 4, the remaining bits are encoded as follows.
'direct_bits' is the amount of remaining bits (from 1 to 30) needed to form
a complete distance, and is calculated as (slot >> 1) - 1. If a distance
needs 6 or more direct_bits, the last 4 bits are encoded separately. The
-last piece (all the direct_bits for distances 4 to 127, or the last 4 bits
-for distances >= 128) is context-coded in reverse order (from LSB to MSB).
-For distances >= 128, the 'direct_bits - 4' part is encoded with fixed 0.5
-probability.
+last piece (all the direct_bits for distances 4 to 127 (slots 4 to 13), or
+the last 4 bits for distances >= 128 (slot >= 14)) is context-coded in
+reverse order (from LSB to MSB). For distances >= 128, the
+'direct_bits - 4' part is encoded with fixed 0.5 probability.
Bit sequence Description
----------------------------------------------------------------------------
@@ -990,12 +1006,11 @@ decoded) and 'code' (representing the current point within 'range').
'range' is initialized to 2^32 - 1, and 'code' is initialized to 0.
The range encoder produces a first 0 byte that must be ignored by the
-range decoder. This is done by shifting 5 bytes in the initialization of
-'code' instead of 4. (See the 'Range_decoder' constructor in the source).
+range decoder. (See the 'Range_decoder' constructor in the source).
-7.4 Decoding and verifying the LZMA stream
-==========================================
+7.4 Decoding and checking the LZMA stream
+=========================================
After decoding the member header and obtaining the dictionary size, the
range decoder is initialized and then the LZMA decoder enters a loop (see
@@ -1005,9 +1020,9 @@ repeated matches, and literal bytes), until the "End Of Stream" marker is
decoded.
Once the "End Of Stream" marker has been decoded, the decompressor reads
-and decodes the member trailer, and verifies that the three integrity
-factors stored there (CRC, data size, and member size) match those computed
-from the data.
+and decodes the member trailer, and checks that the three integrity factors
+stored there (CRC, data size, and member size) match those computed from the
+data.

File: lzip.info, Node: Trailing data, Next: Examples, Prev: Stream format, Up: Top
@@ -1022,12 +1037,13 @@ member. Such trailing data may be:
example when writing to a tape. It is safe to append any amount of
padding zero bytes to a lzip file.
- * Useful data added by the user; a cryptographically secure hash, a
+ * Useful data added by the user; an "End Of File" string (to check that
+ the file has not been truncated), a cryptographically secure hash, a
description of file contents, etc. It is safe to append any amount of
- text to a lzip file as long as none of the first four bytes of the text
- match the corresponding byte in the string "LZIP", and the text does
- not contain any zero bytes (null characters). Nonzero bytes and zero
- bytes can't be safely mixed in trailing data.
+ text to a lzip file as long as none of the first four bytes of the
+ text matches the corresponding byte in the string "LZIP", and the text
+ does not contain any zero bytes (null characters). Nonzero bytes and
+ zero bytes can't be safely mixed in trailing data.
* Garbage added by some not totally successful copy operation.
@@ -1043,7 +1059,7 @@ member. Such trailing data may be:
discriminate trailing data from a corrupt header has a Hamming
distance (HD) of 3, and the 3 bit flips must happen in different magic
bytes for the test to fail. In any case, the option '--trailing-error'
- guarantees that any corrupt header will be detected.
+ guarantees that any corrupt header is detected.
Trailing data are in no way part of the lzip file format, but tools
reading lzip files are expected to behave as correctly and usefully as
@@ -1063,7 +1079,7 @@ File: lzip.info, Node: Examples, Next: Problems, Prev: Trailing data, Up: To
WARNING! Even if lzip is bug-free, other causes may result in a corrupt
compressed file (bugs in the system libraries, memory errors, etc).
Therefore, if the data you are going to compress are important, give the
-option '--keep' to lzip and don't remove the original file until you verify
+option '--keep' to lzip and don't remove the original file until you check
the compressed file with a command like 'lzip -cd file.lz | cmp file -'.
Most RAM errors happening during compression can only be detected by
comparing the compressed file with the original because the corruption
@@ -1096,7 +1112,7 @@ the operation is successful, 'file.lz' is removed.
lzip -d file.lz
-Example 5: Verify the integrity of the compressed file 'file.lz' and show
+Example 5: Check the integrity of the compressed file 'file.lz' and show
status.
lzip -tv file.lz
@@ -1170,7 +1186,7 @@ Appendix A Reference source code
********************************
/* Lzd - Educational decompressor for the lzip format
- Copyright (C) 2013-2022 Antonio Diaz Diaz.
+ Copyright (C) 2013-2024 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -1189,8 +1205,8 @@ Appendix A Reference source code
*/
/*
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 invalid input file.
+ (file not found, invalid command-line options, I/O errors, etc), 2 to
+ indicate a corrupt or invalid input file.
*/
#include <algorithm>
@@ -1301,10 +1317,11 @@ public:
const CRC32 crc32;
-typedef uint8_t Lzip_header[6]; // 0-3 magic bytes
- // 4 version
- // 5 coded dictionary size
-typedef uint8_t Lzip_trailer[20];
+enum { header_size = 6, trailer_size = 20 };
+typedef uint8_t Lzip_header[header_size]; // 0-3 magic bytes
+ // 4 version
+ // 5 coded dictionary size
+typedef uint8_t Lzip_trailer[trailer_size];
// 0-3 CRC32 of the uncompressed data
// 4-11 size of the uncompressed data
// 12-19 member size including header and trailer
@@ -1316,9 +1333,11 @@ class Range_decoder
uint32_t range;
public:
- Range_decoder() : member_pos( 6 ), code( 0 ), range( 0xFFFFFFFFU )
+ Range_decoder()
+ : member_pos( header_size ), code( 0 ), range( 0xFFFFFFFFU )
{
- for( int i = 0; i < 5; ++i ) code = ( code << 8 ) | get_byte();
+ get_byte(); // discard first byte of the LZMA stream
+ for( int i = 0; i < 4; ++i ) code = ( code << 8 ) | get_byte();
}
uint8_t get_byte() { ++member_pos; return std::getc( stdin ); }
@@ -1338,9 +1357,9 @@ public:
return symbol;
}
- unsigned decode_bit( Bit_model & bm )
+ bool decode_bit( Bit_model & bm )
{
- unsigned symbol;
+ bool symbol;
const uint32_t bound = ( range >> bit_model_total_bits ) * bm.probability;
if( code < bound )
{
@@ -1351,8 +1370,8 @@ public:
}
else
{
- range -= bound;
code -= bound;
+ range -= bound;
bm.probability -= bm.probability >> bit_model_move_bits;
symbol = 1;
}
@@ -1386,8 +1405,8 @@ public:
unsigned symbol = 1;
for( int i = 7; i >= 0; --i )
{
- const unsigned match_bit = ( match_byte >> i ) & 1;
- const unsigned bit = decode_bit( bm[symbol+(match_bit<<8)+0x100] );
+ const bool match_bit = ( match_byte >> i ) & 1;
+ const bool bit = decode_bit( bm[symbol+(match_bit<<8)+0x100] );
symbol = ( symbol << 1 ) | bit;
if( match_bit != bit )
{
@@ -1402,11 +1421,12 @@ public:
unsigned decode_len( Len_model & lm, const int pos_state )
{
if( decode_bit( lm.choice1 ) == 0 )
- return decode_tree( lm.bm_low[pos_state], len_low_bits );
+ return min_match_len +
+ decode_tree( lm.bm_low[pos_state], len_low_bits );
if( decode_bit( lm.choice2 ) == 0 )
- return len_low_symbols +
+ return min_match_len + len_low_symbols +
decode_tree( lm.bm_mid[pos_state], len_mid_bits );
- return len_low_symbols + len_mid_symbols +
+ return min_match_len + len_low_symbols + len_mid_symbols +
decode_tree( lm.bm_high, len_high_bits );
}
};
@@ -1479,7 +1499,7 @@ void LZ_decoder::flush_data()
}
-bool LZ_decoder::decode_member() // Returns false if error
+bool LZ_decoder::decode_member() // Return false if error
{
Bit_model bm_literal[1<<literal_context_bits][0x300];
Bit_model bm_match[State::states][pos_states];
@@ -1541,12 +1561,12 @@ bool LZ_decoder::decode_member() // Returns false if error
rep0 = distance;
}
state.set_rep();
- len = min_match_len + rdec.decode_len( rep_len_model, pos_state );
+ len = rdec.decode_len( rep_len_model, pos_state );
}
else // match
{
rep3 = rep2; rep2 = rep1; rep1 = rep0;
- len = min_match_len + rdec.decode_len( match_len_model, pos_state );
+ len = rdec.decode_len( match_len_model, pos_state );
const int len_state = std::min( len - min_match_len, len_states - 1 );
rep0 = rdec.decode_tree( bm_dis_slot[len_state], dis_slot_bits );
if( rep0 >= start_dis_model )
@@ -1565,7 +1585,7 @@ bool LZ_decoder::decode_member() // Returns false if error
if( rep0 == 0xFFFFFFFFU ) // marker found
{
flush_data();
- return ( len == min_match_len ); // End Of Stream marker
+ return len == min_match_len; // End Of Stream marker
}
}
}
@@ -1586,11 +1606,11 @@ int main( const int argc, const char * const argv[] )
{
std::printf(
"Lzd %s - Educational decompressor for the lzip format.\n"
- "Study the source to learn how a lzip decompressor works.\n"
+ "Study the source code to learn how a lzip decompressor works.\n"
"See the lzip manual for an explanation of the code.\n"
"\nUsage: %s [-d] < file.lz > file\n"
"Lzd decompresses from standard input to standard output.\n"
- "\nCopyright (C) 2022 Antonio Diaz Diaz.\n"
+ "\nCopyright (C) 2024 Antonio Diaz Diaz.\n"
"License 2-clause BSD.\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"
@@ -1607,8 +1627,8 @@ int main( const int argc, const char * const argv[] )
for( bool first_member = true; ; first_member = false )
{
- Lzip_header header; // verify header
- for( int i = 0; i < 6; ++i ) header[i] = std::getc( stdin );
+ Lzip_header header; // check header
+ for( int i = 0; i < header_size; ++i ) header[i] = std::getc( stdin );
if( std::feof( stdin ) || std::memcmp( header, "LZIP\x01", 5 ) != 0 )
{
if( first_member )
@@ -1626,8 +1646,8 @@ int main( const int argc, const char * const argv[] )
if( !decoder.decode_member() )
{ std::fputs( "Data error\n", stderr ); return 2; }
- Lzip_trailer trailer; // verify trailer
- for( int i = 0; i < 20; ++i ) trailer[i] = decoder.get_byte();
+ Lzip_trailer trailer; // check trailer
+ for( int i = 0; i < trailer_size; ++i ) trailer[i] = decoder.get_byte();
int retval = 0;
unsigned crc = 0;
for( int i = 3; i >= 0; --i ) crc = ( crc << 8 ) + trailer[i];
@@ -1683,22 +1703,22 @@ Concept index

Tag Table:
Node: Top203
-Node: Introduction1198
-Node: Output6972
-Node: Invoking lzip8567
-Ref: --trailing-error9356
-Node: Quality assurance18682
-Node: Algorithm27705
-Node: File format31109
-Ref: coded-dict-size32538
-Node: Stream format33773
-Ref: what-is-coded36169
-Node: Trailing data45097
-Node: Examples47358
-Ref: concat-example48800
-Node: Problems50021
-Node: Reference source code50553
-Node: Concept index65411
+Node: Introduction1202
+Node: Output7087
+Node: Invoking lzip8682
+Ref: --trailing-error9551
+Node: Quality assurance19649
+Node: Algorithm28462
+Node: File format31863
+Ref: coded-dict-size33292
+Node: Stream format34523
+Ref: what-is-coded36918
+Node: Trailing data45792
+Node: Examples48128
+Ref: concat-example49568
+Node: Problems50789
+Node: Reference source code51321
+Node: Concept index66366

End Tag Table
diff --git a/doc/lzip.texi b/doc/lzip.texi
index 144b525..7e6223c 100644
--- a/doc/lzip.texi
+++ b/doc/lzip.texi
@@ -6,8 +6,8 @@
@finalout
@c %**end of header
-@set UPDATED 24 January 2022
-@set VERSION 1.23
+@set UPDATED 19 January 2024
+@set VERSION 1.24-rc2
@dircategory Compression
@direntry
@@ -38,7 +38,7 @@ This manual is for Lzip (version @value{VERSION}, @value{UPDATED}).
@menu
* Introduction:: Purpose and features of lzip
* Output:: Meaning of lzip's output
-* Invoking lzip:: Command line interface
+* Invoking lzip:: Command-line interface
* Quality assurance:: Design, development, and testing of lzip
* Algorithm:: How lzip compresses the data
* File format:: Detailed format of the compressed file
@@ -51,7 +51,7 @@ This manual is for Lzip (version @value{VERSION}, @value{UPDATED}).
@end menu
@sp 1
-Copyright @copyright{} 2008-2022 Antonio Diaz Diaz.
+Copyright @copyright{} 2008-2024 Antonio Diaz Diaz.
This manual is free documentation: you have unlimited permission to copy,
distribute, and modify it.
@@ -65,14 +65,15 @@ distribute, and modify it.
@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip}
is a lossless data compressor with a user interface similar to the one
of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov
-chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity
-checking to maximize interoperability and optimize safety. Lzip can compress
-about as fast as gzip @w{(lzip -0)} or compress most files more than bzip2
-@w{(lzip -9)}. Decompression speed is intermediate between gzip and bzip2.
-Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip
-has been designed, written, and tested with great care to replace gzip and
-bzip2 as the standard general-purpose compressed format for unix-like
-systems.
+chain-Algorithm' (LZMA) stream format to maximize interoperability. The
+maximum dictionary size is 512 MiB so that any lzip file can be decompressed
+on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
+checking. Lzip can compress about as fast as gzip @w{(lzip -0)} or compress most
+files more than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between
+gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery
+perspective. Lzip has been designed, written, and tested with great care to
+replace gzip and bzip2 as the standard general-purpose compressed format for
+Unix-like systems.
For compressing/decompressing large files on multiprocessor machines
@uref{http://www.nongnu.org/lzip/manual/plzip_manual.html,,plzip} can be
@@ -122,30 +123,29 @@ the nearer it is from the beginning of the file. Therefore, with the help of
lziprecover, losing an entire archive just because of a corrupt byte near
the beginning is a thing of the past.
-The member trailer stores the 32-bit CRC of the original data, the size
-of the original data, and the size of the member. These values, together
-with the "End Of Stream" marker, provide a 3 factor integrity checking
-which guarantees that the decompressed version of the data is identical
-to the original. This guards against corruption of the compressed data,
-and against undetected bugs in lzip (hopefully very unlikely). The
-chances of data corruption going undetected are microscopic. Be aware,
-though, that the check occurs upon decompression, so it can only tell
-you that something is wrong. It can't help you recover the original
-uncompressed data.
+The member trailer stores the 32-bit CRC of the original data, the size of
+the original data, and the size of the member. These values, together with
+the "End Of Stream" marker, provide a 3-factor integrity checking which
+guarantees that the decompressed version of the data is identical to the
+original. This guards against corruption of the compressed data, and against
+undetected bugs in lzip (hopefully very unlikely). The chances of data
+corruption going undetected are microscopic. Be aware, though, that the
+check occurs upon decompression, so it can only tell you that something is
+wrong. It can't help you recover the original uncompressed data.
Lzip uses the same well-defined exit status values used by bzip2, which
makes it safer than compressors returning ambiguous warning values (like
gzip) when it is used as a back end for other programs like tar or zutils.
-Lzip will automatically use for each file the largest dictionary size that
-does not exceed neither the file size nor the limit given. Keep in mind that
-the decompression memory requirement is affected at compression time by the
+Lzip automatically uses for each file the largest dictionary size that does
+not exceed neither the file size nor the limit given. Keep in mind that the
+decompression memory requirement is affected at compression time by the
choice of dictionary size limit.
The amount of memory required for compression is about 1 or 2 times the
dictionary size limit (1 if input file size is less than dictionary size
limit, else 2) plus 9 times the dictionary size really used. The option
-@samp{-0} is special and only requires about @w{1.5 MiB} at most. The
+@option{-0} is special and only requires about @w{1.5 MiB} at most. The
amount of memory required for decompression is about @w{46 kB} larger
than the dictionary size really used.
@@ -161,19 +161,19 @@ file from that of the compressed file as follows:
@end multitable
(De)compressing a file is much like copying or moving it. Therefore lzip
-preserves the access and modification dates, permissions, and, when
-possible, ownership of the file just as @w{@samp{cp -p}} does. (If the user ID or
-the group ID can't be duplicated, the file permission bits S_ISUID and
-S_ISGID are cleared).
+preserves the access and modification dates, permissions, and, if you have
+appropriate privileges, ownership of the file just as @w{@samp{cp -p}} does.
+(If the user ID or the group ID can't be duplicated, the file permission
+bits S_ISUID and S_ISGID are cleared).
Lzip is able to read from some types of non-regular files if either the
-option @samp{-c} or the option @samp{-o} is specified.
+option @option{-c} or the option @option{-o} is specified.
-Lzip will refuse to read compressed data from a terminal or write compressed
+Lzip refuses to read compressed data from a terminal or write compressed
data to a terminal, as this would be entirely incomprehensible and might
leave the terminal in an abnormal state.
-Lzip will correctly decompress a file which is the concatenation of two or
+Lzip correctly decompresses a file which is the concatenation of two or
more compressed files. The result is the concatenation of the corresponding
decompressed files. Integrity testing of concatenated compressed files is
also supported.
@@ -255,7 +255,8 @@ lzip [@var{options}] [@var{files}]
If no file names are specified, lzip compresses (or decompresses) from
standard input to standard output. A hyphen @samp{-} used as a @var{file}
argument means standard input. It can be mixed with other @var{files} and is
-read just once, the first time it appears in the command line.
+read just once, the first time it appears in the command line. Remember to
+prepend @file{./} to any file name beginning with a hyphen, or use @samp{--}.
lzip supports the following
@uref{http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#Argument-syntax,,options}:
@@ -293,19 +294,20 @@ compression ratio, so use it only when needed. Valid values range from
Compress or decompress to standard output; keep input files unchanged. If
compressing several files, each file is compressed independently. (The
output consists of a sequence of independently compressed members). This
-option (or @samp{-o}) is needed when reading from a named pipe (fifo) or
+option (or @option{-o}) is needed when reading from a named pipe (fifo) or
from a device. Use it also to recover as much of the decompressed data as
-possible when decompressing a corrupt file. @samp{-c} overrides @samp{-o}
-and @samp{-S}. @samp{-c} has no effect when testing or listing.
+possible when decompressing a corrupt file. @option{-c} overrides @option{-o}
+and @option{-S}. @option{-c} has no effect when testing or listing.
@item -d
@itemx --decompress
-Decompress the files specified. If a file does not exist, can't be opened,
-or the destination file already exists and @samp{--force} has not been
-specified, lzip continues decompressing the rest of the files and exits with
-error status 1. If a file fails to decompress, or is a terminal, lzip exits
-immediately with error status 2 without decompressing the rest of the files.
-A terminal is considered an uncompressed file, and therefore invalid.
+Decompress the files specified. The integrity of the files specified is
+checked. If a file does not exist, can't be opened, or the destination file
+already exists and @option{--force} has not been specified, lzip continues
+decompressing the rest of the files and exits with error status 1. If a file
+fails to decompress, or is a terminal, lzip exits immediately with error
+status 2 without decompressing the rest of the files. A terminal is
+considered an uncompressed file, and therefore invalid.
@item -f
@itemx --force
@@ -325,38 +327,39 @@ Keep (don't delete) input files during compression or decompression.
Print the uncompressed size, compressed size, and percentage saved of the
files specified. Trailing data are ignored. The values produced are correct
even for multimember files. If more than one file is given, a final line
-containing the cumulative sizes is printed. With @samp{-v}, the dictionary
+containing the cumulative sizes is printed. With @option{-v}, the dictionary
size, the number of members in the file, and the amount of trailing data (if
-any) are also printed. With @samp{-vv}, the positions and sizes of each
+any) are also printed. With @option{-vv}, the positions and sizes of each
member in multimember files are also printed.
If any file is damaged, does not exist, can't be opened, or is not regular,
-the final exit status will be @w{> 0}. @samp{-lq} can be used to verify
-quickly (without decompressing) the structural integrity of the files
-specified. (Use @samp{--test} to verify the data integrity). @samp{-alq}
-additionally verifies that none of the files specified contain trailing data.
+the final exit status is @w{> 0}. @option{-lq} can be used to check quickly
+(without decompressing) the structural integrity of the files specified.
+(Use @option{--test} to check the data integrity). @option{-alq}
+additionally checks that none of the files specified contain trailing data.
@item -m @var{bytes}
@itemx --match-length=@var{bytes}
-When compressing, set the match length limit in bytes. After a match
-this long is found, the search is finished. Valid values range from 5 to
-273. Larger values usually give better compression ratios but longer
-compression times.
+When compressing, set the match length limit in bytes. After a match this
+long is found, the search is finished. Valid values range from 5 to 273.
+Larger values usually give better compression ratios but longer compression
+times.
@item -o @var{file}
@itemx --output=@var{file}
-If @samp{-c} has not been also specified, write the (de)compressed output to
-@var{file}; keep input files unchanged. If compressing several files, each
-file is compressed independently. (The output consists of a sequence of
-independently compressed members). This option (or @samp{-c}) is needed when
-reading from a named pipe (fifo) or from a device. @w{@samp{-o -}} is
-equivalent to @samp{-c}. @samp{-o} has no effect when testing or listing.
+If @option{-c} has not been also specified, write the (de)compressed output
+to @var{file}, automatically creating any missing parent directories; keep
+input files unchanged. If compressing several files, each file is compressed
+independently. (The output consists of a sequence of independently
+compressed members). This option (or @option{-c}) is needed when reading
+from a named pipe (fifo) or from a device. @w{@option{-o -}} is equivalent
+to @option{-c}. @option{-o} has no effect when testing or listing.
In order to keep backward compatibility with lzip versions prior to 1.22,
when compressing from standard input and no other file names are given, the
extension @samp{.lz} is appended to @var{file} unless it already ends in
@samp{.lz} or @samp{.tlz}. This feature will be removed in a future version
-of lzip. Meanwhile, redirection may be used instead of @samp{-o} to write
+of lzip. Meanwhile, redirection may be used instead of @option{-o} to write
the compressed output to a file without the extension @samp{.lz} in its
name: @w{@samp{lzip < file > foo}}.
@@ -371,14 +374,14 @@ Quiet operation. Suppress all messages.
@item -s @var{bytes}
@itemx --dictionary-size=@var{bytes}
-When compressing, set the dictionary size limit in bytes. Lzip will use
-for each file the largest dictionary size that does not exceed neither
-the file size nor this limit. Valid values range from @w{4 KiB} to
-@w{512 MiB}. Values 12 to 29 are interpreted as powers of two, meaning
-2^12 to 2^29 bytes. Dictionary sizes are quantized so that they can be
-coded in just one byte (@pxref{coded-dict-size}). If the size specified
-does not match one of the valid sizes, it will be rounded upwards by
-adding up to @w{(@var{bytes} / 8)} to it.
+When compressing, set the dictionary size limit in bytes. Lzip uses for
+each file the largest dictionary size that does not exceed neither the file
+size nor this limit. Valid values range from @w{4 KiB} to @w{512 MiB}.
+Values 12 to 29 are interpreted as powers of two, meaning 2^12 to 2^29
+bytes. Dictionary sizes are quantized so that they can be coded in just one
+byte (@pxref{coded-dict-size}). If the size specified does not match one of
+the valid sizes, it is rounded upwards by adding up to @w{(@var{bytes} / 8)}
+to it.
For maximum compression you should use a dictionary size limit as large
as possible, but keep in mind that the decompression memory requirement
@@ -386,7 +389,7 @@ is affected at compression time by the choice of dictionary size limit.
@item -S @var{bytes}
@itemx --volume-size=@var{bytes}
-When compressing, and @samp{-c} has not been also specified, split the
+When compressing, and @option{-c} has not been also specified, split the
compressed output into several volume files with names
@samp{original_name00001.lz}, @samp{original_name00002.lz}, etc, and set the
volume size limit to @var{bytes}. Input files are kept unchanged. Each
@@ -398,11 +401,11 @@ from @w{100 kB} to @w{4 EiB}.
@itemx --test
Check integrity of the files specified, but don't decompress them. This
really performs a trial decompression and throws away the result. Use it
-together with @samp{-v} to see information about the files. If a file
+together with @option{-v} to see information about the files. If a file
fails the test, does not exist, can't be opened, or is a terminal, lzip
-continues checking the rest of the files. A final diagnostic is shown at
-verbosity level 1 or higher if any file fails the test when testing
-multiple files.
+continues testing the rest of the files. A final diagnostic is shown at
+verbosity level 1 or higher if any file fails the test when testing multiple
+files.
@item -v
@itemx --verbose
@@ -414,23 +417,23 @@ verbosity level, showing status, compression ratio, dictionary size,
trailer contents (CRC, data size, member size), and up to 6 bytes of
trailing data (if any) both in hexadecimal and as a string of printable
ASCII characters.@*
-Two or more @samp{-v} options show the progress of (de)compression.
+Two or more @option{-v} options show the progress of (de)compression.
@item -0 .. -9
Compression level. Set the compression parameters (dictionary size and
match length limit) as shown in the table below. The default compression
-level is @samp{-6}, equivalent to @w{@samp{-s8MiB -m36}}. Note that
-@samp{-9} can be much slower than @samp{-0}. These options have no
+level is @option{-6}, equivalent to @w{@option{-s8MiB -m36}}. Note that
+@option{-9} can be much slower than @option{-0}. These options have no
effect when decompressing, testing, or listing.
-The bidimensional parameter space of LZMA can't be mapped to a linear
-scale optimal for all files. If your files are large, very repetitive,
-etc, you may need to use the options @samp{--dictionary-size} and
-@samp{--match-length} directly to achieve optimal performance.
+The bidimensional parameter space of LZMA can't be mapped to a linear scale
+optimal for all files. If your files are large, very repetitive, etc, you
+may need to use the options @option{--dictionary-size} and
+@option{--match-length} directly to achieve optimal performance.
-If several compression levels or @samp{-s} or @samp{-m} options are
-given, the last setting is used. For example @w{@samp{-9 -s64MiB}} is
-equivalent to @w{@samp{-s64MiB -m273}}
+If several compression levels or @option{-s} or @option{-m} options are
+given, the last setting is used. For example @w{@option{-9 -s64MiB}} is
+equivalent to @w{@option{-s64MiB -m273}}
@multitable {Level} {Dictionary size (-s)} {Match length limit (-m)}
@item Level @tab Dictionary size (-s) @tab Match length limit (-m)
@@ -450,6 +453,15 @@ equivalent to @w{@samp{-s64MiB -m273}}
@itemx --best
Aliases for GNU gzip compatibility.
+@item --empty-error
+Exit with error status 2 if any empty member is found in the input files.
+
+@item --marking-error
+Exit with error status 2 if the first LZMA byte is non-zero in any member of
+the input files. This may be caused by data corruption or by deliberate
+insertion of tracking information in the file. Use
+@w{@samp{lziprecover --clear-marking}} to clear any such non-zero bytes.
+
@item --loose-trailing
When decompressing, testing, or listing, allow trailing data whose first
bytes are so similar to the magic bytes of a lzip header that they can
@@ -458,28 +470,31 @@ be confused with a corrupt header. Use this option if a file triggers a
@end table
-Numbers given as arguments to options may be followed by a multiplier
-and an optional @samp{B} for "byte".
+Numbers given as arguments to options may be expressed in decimal,
+hexadecimal, or octal (using the same syntax as integer constants in C++),
+and may be followed by a multiplier and an optional @samp{B} for "byte".
Table of SI and binary prefixes (unit multipliers):
-@multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)}
+@multitable {Prefix} {kilobyte (10^3 = 1000)} {|} {Prefix} {kibibyte (2^10 = 1024)}
@item Prefix @tab Value @tab | @tab Prefix @tab Value
-@item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024)
-@item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20)
-@item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30)
-@item T @tab terabyte (10^12) @tab | @tab Ti @tab tebibyte (2^40)
-@item P @tab petabyte (10^15) @tab | @tab Pi @tab pebibyte (2^50)
-@item E @tab exabyte (10^18) @tab | @tab Ei @tab exbibyte (2^60)
-@item Z @tab zettabyte (10^21) @tab | @tab Zi @tab zebibyte (2^70)
-@item Y @tab yottabyte (10^24) @tab | @tab Yi @tab yobibyte (2^80)
+@item k @tab kilobyte (10^3 = 1000) @tab | @tab Ki @tab kibibyte (2^10 = 1024)
+@item M @tab megabyte (10^6) @tab | @tab Mi @tab mebibyte (2^20)
+@item G @tab gigabyte (10^9) @tab | @tab Gi @tab gibibyte (2^30)
+@item T @tab terabyte (10^12) @tab | @tab Ti @tab tebibyte (2^40)
+@item P @tab petabyte (10^15) @tab | @tab Pi @tab pebibyte (2^50)
+@item E @tab exabyte (10^18) @tab | @tab Ei @tab exbibyte (2^60)
+@item Z @tab zettabyte (10^21) @tab | @tab Zi @tab zebibyte (2^70)
+@item Y @tab yottabyte (10^24) @tab | @tab Yi @tab yobibyte (2^80)
+@item R @tab ronnabyte (10^27) @tab | @tab Ri @tab robibyte (2^90)
+@item Q @tab quettabyte (10^30) @tab | @tab Qi @tab quebibyte (2^100)
@end multitable
@sp 1
-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 invalid
-input file, 3 for an internal consistency error (e.g., bug) which caused
-lzip to panic.
+Exit status: 0 for a normal exit, 1 for environmental problems
+(file not found, invalid command-line options, I/O errors, etc), 2 to
+indicate a corrupt or invalid input file, 3 for an internal consistency
+error (e.g., bug) which caused lzip to panic.
@node Quality assurance
@@ -492,17 +507,12 @@ make it so complicated that there are no obvious deficiencies. The first
method is far more difficult.@*
--- C.A.R. Hoare
-Lzip is developed by volunteers who lack the resources required for
-extensive testing in all circumstances. It is up to you to test lzip before
-using it in mission-critical applications. However, a compressor like lzip
-is not a toy, and maintaining it is not a hobby. Many people's data depend
-on it. Therefore the lzip file format has been reviewed carefully and is
-believed to be free from negligent design errors.
-
Lzip has been designed, written, and tested with great care to replace gzip
-and bzip2 as the standard general-purpose compressed format for unix-like
+and bzip2 as the standard general-purpose compressed format for Unix-like
systems. This chapter describes the lessons learned from these previous
-formats, and their application to the design of lzip.
+formats, and their application to the design of lzip. The lzip format
+specification has been reviewed carefully and is believed to be free from
+design errors.
@sp 1
@section Format design
@@ -587,9 +597,9 @@ compressed blocks.
Using an optional CRC for the header is not only a bad idea, it is an error;
it circumvents the Hamming distance (HD) of the CRC and may prevent the
extraction of perfectly good data. For example, if the CRC is used and the
-bit enabling it is reset by a bit flip, the header will appear to be intact
-(in spite of being corrupt) while the compressed blocks will appear to be
-totally unrecoverable (in spite of being intact). Very misleading indeed.
+bit enabling it is reset by a bit flip, then the header seems to be intact
+(in spite of being corrupt) while the compressed blocks seem to be totally
+unrecoverable (in spite of being intact). Very misleading indeed.
@item Metadata
@@ -607,7 +617,7 @@ from identical input).
Probably the most frequently reported shortcoming of the gzip format is that
it only stores the least significant 32 bits of the uncompressed size. The
-size of any file larger than @w{4 GiB} gets truncated.
+size of any file larger or equal than @w{4 GiB} gets truncated.
Bzip2 does not store the uncompressed size of the file.
@@ -630,10 +640,14 @@ and may limit the number of members or the total uncompressed size.
@section Quality of implementation
+Our civilization depends critically on software; it had better be quality
+software.@*
+--- Bjarne Stroustrup
+
@table @samp
@item Accurate and robust error detection
-The lzip format provides 3 factor integrity checking, and the decompressors
+The lzip format provides 3-factor integrity checking, and the decompressors
report mismatches in each factor separately. This method detects most false
positives for corruption. If just one byte in one factor fails but the other
two factors match the data, it probably means that the data are intact and
@@ -642,14 +656,14 @@ member size) in the member trailer.
@item Multiple implementations
-Just like the lzip format provides 3 factor protection against undetected
+Just like the lzip format provides 3-factor protection against undetected
data corruption, the development methodology of the lzip family of
-compressors provides 3 factor protection against undetected programming
+compressors provides 3-factor protection against undetected programming
errors.
Three related but independent compressor implementations, lzip, clzip, and
minilzip/lzlib, are developed concurrently. Every stable release of any of
-them is tested to verify that it produces identical output to the other two.
+them is tested to check that it produces identical output to the other two.
This guarantees that all three implement the same algorithm, and makes it
unlikely that any of them may contain serious undiscovered errors. In fact,
no errors have been discovered in lzip since 2009.
@@ -686,7 +700,7 @@ concrete algorithm; it is more like "any algorithm using the LZMA coding
scheme". LZMA compression consists in describing the uncompressed data as a
succession of coding sequences from the set shown in Section @samp{What is
coded} (@pxref{what-is-coded}), and then encoding them using a range
-encoder. For example, the option @samp{-0} of lzip uses the scheme in almost
+encoder. For example, the option @option{-0} of lzip uses the scheme in almost
the simplest way possible; issuing the longest match it can find, or a
literal byte if it can't find a match. Inversely, a much more elaborated way
of finding coding sequences of minimum size than the one currently used by
@@ -694,13 +708,13 @@ lzip could be developed, and the resulting sequence could also be coded
using the LZMA coding scheme.
Lzip currently implements two variants of the LZMA algorithm: fast
-(used by option @samp{-0}) and normal (used by all other compression levels).
+(used by option @option{-0}) and normal (used by all other compression levels).
The high compression of LZMA comes from combining two basic, well-proven
-compression ideas: sliding dictionaries (LZ77/78) and markov models (the
-thing used by every compression algorithm that uses a range encoder or
-similar order-0 entropy coder as its last stage) with segregation of
-contexts according to what the bits are used for.
+compression ideas: sliding dictionaries (LZ77) and markov models (the thing
+used by every compression algorithm that uses a range encoder or similar
+order-0 entropy coder as its last stage) with segregation of contexts
+according to what the bits are used for.
Lzip is a two stage compressor. The first stage is a Lempel-Ziv coder,
which reduces redundancy by translating chunks of data to their
@@ -746,7 +760,7 @@ get longer with higher compression levels because dictionary size increases
@noindent
The ideas embodied in lzip are due to (at least) the following people:
-Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the
+Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the
definition of Markov chains), G.N.N. Martin (for the definition of range
encoding), Igor Pavlov (for putting all the above together in LZMA), and
Julian Seward (for bzip2's CLI).
@@ -780,7 +794,7 @@ represents one byte; a box like this:
represents a variable number of bytes.
@sp 1
-A lzip file consists of a series of independent "members" (compressed data
+A lzip file consists of one or more independent "members" (compressed data
sets). The members simply appear one after another in the file, with no
additional information before, between, or after them. Each member can
encode in compressed form up to @w{16 EiB - 1 byte} of uncompressed data.
@@ -826,10 +840,10 @@ Size of the original uncompressed data.
@item Member size (8 bytes)
Total size of the member, including header and trailer. This field acts
-as a distributed index, allows the verification of stream integrity, and
+as a distributed index, improves the checking of stream integrity, and
facilitates the safe recovery of undamaged members from multimember files.
-Member size should be limited to @w{2 PiB} to prevent the data size field
-from overflowing.
+Lzip limits the member size to @w{2 PiB} to prevent the data size field from
+overflowing.
@end table
@@ -849,12 +863,12 @@ does not even appear in the code.
Lzip finishes the LZMA stream with an "End Of Stream" (EOS) marker (the
distance-length pair @w{0xFFFFFFFFU, 2}), which in conjunction with the
-@samp{member size} field in the member trailer allows the verification of
-stream integrity. The EOS marker is the only marker allowed in lzip files.
-The LZMA stream in lzip files always has these two features (default
-properties and EOS marker) and is referred to in this document as
-LZMA-302eos. This simplified form of the LZMA stream format has been chosen
-to maximize interoperability and safety.
+@samp{member size} field in the member trailer allows the checking of stream
+integrity. The EOS marker is the only LZMA marker allowed in lzip files. The
+LZMA stream in lzip files always has these two features (default properties
+and EOS marker) and is referred to in this document as LZMA-302eos. This
+simplified and marker-terminated form of the LZMA stream format has been
+chosen to maximize interoperability and safety.
The second stage of LZMA is a range encoder that uses a different
probability model for each type of symbol: distances, lengths, literal
@@ -872,9 +886,9 @@ code of a real decompressor seems the only appropriate reference to use.
What follows is a description of the decoding algorithm for LZMA-302eos
streams using as reference the source code of "lzd", an educational
-decompressor for lzip files which can be downloaded from the lzip download
-directory. Lzd is written in C++11 and its source code is included in
-appendix A. @xref{Reference source code}.
+decompressor for lzip files, included in appendix A. @xref{Reference source
+code}. Lzd is written in C++11 and can be downloaded from the lzip download
+directory.
@sp 1
@section What is coded
@@ -941,17 +955,17 @@ the distance is @w{>= 4}, the remaining bits are encoded as follows.
@samp{direct_bits} is the amount of remaining bits (from 1 to 30) needed
to form a complete distance, and is calculated as @w{(slot >> 1) - 1}.
If a distance needs 6 or more direct_bits, the last 4 bits are encoded
-separately. The last piece (all the direct_bits for distances 4 to 127,
-or the last 4 bits for distances @w{>= 128}) is context-coded in reverse
-order (from LSB to MSB). For distances @w{>= 128}, the
-@w{@samp{direct_bits - 4}} part is encoded with fixed 0.5 probability.
+separately. The last piece (all the direct_bits for distances 4 to 127
+(slots 4 to 13), or the last 4 bits for distances @w{>= 128}
+@w{(slot >= 14)}) is context-coded in reverse order (from LSB to MSB). For
+distances @w{>= 128}, the @w{@samp{direct_bits - 4}} part is encoded with
+fixed 0.5 probability.
@multitable @columnfractions .5 .5
@headitem Bit sequence @tab Description
@item slot @tab distances from 0 to 3
@item slot + direct_bits @tab distances from 4 to 127
-@item slot + (direct_bits - 4) + 4 bits @tab distances from 128 to
-2^32 - 1
+@item slot + (direct_bits - 4) + 4 bits @tab distances from 128 to 2^32 - 1
@end multitable
@sp 1
@@ -1067,12 +1081,10 @@ not yet decoded) and @samp{code} (representing the current point within
@samp{code} is initialized to 0.
The range encoder produces a first 0 byte that must be ignored by the
-range decoder. This is done by shifting 5 bytes in the initialization of
-@samp{code} instead of 4. (See the @samp{Range_decoder} constructor in
-the source).
+range decoder. (See the @samp{Range_decoder} constructor in the source).
@sp 1
-@section Decoding and verifying the LZMA stream
+@section Decoding and checking the LZMA stream
After decoding the member header and obtaining the dictionary size, the
range decoder is initialized and then the LZMA decoder enters a loop
@@ -1082,7 +1094,7 @@ sequences (matches, repeated matches, and literal bytes), until the "End
Of Stream" marker is decoded.
Once the "End Of Stream" marker has been decoded, the decompressor reads and
-decodes the member trailer, and verifies that the three integrity factors
+decodes the member trailer, and checks that the three integrity factors
stored there (CRC, data size, and member size) match those computed from the
data.
@@ -1101,12 +1113,13 @@ example when writing to a tape. It is safe to append any amount of
padding zero bytes to a lzip file.
@item
-Useful data added by the user; a cryptographically secure hash, a
-description of file contents, etc. It is safe to append any amount of
-text to a lzip file as long as none of the first four bytes of the text
-match the corresponding byte in the string "LZIP", and the text does not
-contain any zero bytes (null characters). Nonzero bytes and zero bytes
-can't be safely mixed in trailing data.
+Useful data added by the user; an "End Of File" string (to check that the
+file has not been truncated), a cryptographically secure hash, a description
+of file contents, etc. It is safe to append any amount of text to a lzip
+file as long as none of the first four bytes of the text matches the
+corresponding byte in the string "LZIP", and the text does not contain any
+zero bytes (null characters). Nonzero bytes and zero bytes can't be safely
+mixed in trailing data.
@item
Garbage added by some not totally successful copy operation.
@@ -1124,8 +1137,8 @@ integrity information itself. Therefore it can be considered to be below
the noise level. Additionally, the test used by lzip to discriminate
trailing data from a corrupt header has a Hamming distance (HD) of 3,
and the 3 bit flips must happen in different magic bytes for the test to
-fail. In any case, the option @samp{--trailing-error} guarantees that
-any corrupt header will be detected.
+fail. In any case, the option @option{--trailing-error} guarantees that
+any corrupt header is detected.
@end itemize
Trailing data are in no way part of the lzip file format, but tools
@@ -1135,7 +1148,7 @@ possible in the presence of trailing data.
Trailing data can be safely ignored in most cases. In some cases, like
that of user-added data, they are expected to be ignored. In those cases
where a file containing trailing data must be rejected, the option
-@samp{--trailing-error} can be used. @xref{--trailing-error}.
+@option{--trailing-error} can be used. @xref{--trailing-error}.
@node Examples
@@ -1145,8 +1158,8 @@ where a file containing trailing data must be rejected, the option
WARNING! Even if lzip is bug-free, other causes may result in a corrupt
compressed file (bugs in the system libraries, memory errors, etc).
Therefore, if the data you are going to compress are important, give the
-option @samp{--keep} to lzip and don't remove the original file until you
-verify the compressed file with a command like
+option @option{--keep} to lzip and don't remove the original file until you
+check the compressed file with a command like
@w{@samp{lzip -cd file.lz | cmp file -}}. Most RAM errors happening during
compression can only be detected by comparing the compressed file with the
original because the corruption happens before lzip compresses the RAM
@@ -1191,7 +1204,7 @@ lzip -d file.lz
@sp 1
@noindent
-Example 5: Verify the integrity of the compressed file @samp{file.lz} and
+Example 5: Check the integrity of the compressed file @samp{file.lz} and
show status.
@example
@@ -1289,7 +1302,7 @@ find by running @w{@samp{lzip --version}}.
@verbatim
/* Lzd - Educational decompressor for the lzip format
- Copyright (C) 2013-2022 Antonio Diaz Diaz.
+ Copyright (C) 2013-2024 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -1308,8 +1321,8 @@ find by running @w{@samp{lzip --version}}.
*/
/*
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 invalid input file.
+ (file not found, invalid command-line options, I/O errors, etc), 2 to
+ indicate a corrupt or invalid input file.
*/
#include <algorithm>
@@ -1420,10 +1433,11 @@ public:
const CRC32 crc32;
-typedef uint8_t Lzip_header[6]; // 0-3 magic bytes
- // 4 version
- // 5 coded dictionary size
-typedef uint8_t Lzip_trailer[20];
+enum { header_size = 6, trailer_size = 20 };
+typedef uint8_t Lzip_header[header_size]; // 0-3 magic bytes
+ // 4 version
+ // 5 coded dictionary size
+typedef uint8_t Lzip_trailer[trailer_size];
// 0-3 CRC32 of the uncompressed data
// 4-11 size of the uncompressed data
// 12-19 member size including header and trailer
@@ -1435,9 +1449,11 @@ class Range_decoder
uint32_t range;
public:
- Range_decoder() : member_pos( 6 ), code( 0 ), range( 0xFFFFFFFFU )
+ Range_decoder()
+ : member_pos( header_size ), code( 0 ), range( 0xFFFFFFFFU )
{
- for( int i = 0; i < 5; ++i ) code = ( code << 8 ) | get_byte();
+ get_byte(); // discard first byte of the LZMA stream
+ for( int i = 0; i < 4; ++i ) code = ( code << 8 ) | get_byte();
}
uint8_t get_byte() { ++member_pos; return std::getc( stdin ); }
@@ -1457,9 +1473,9 @@ public:
return symbol;
}
- unsigned decode_bit( Bit_model & bm )
+ bool decode_bit( Bit_model & bm )
{
- unsigned symbol;
+ bool symbol;
const uint32_t bound = ( range >> bit_model_total_bits ) * bm.probability;
if( code < bound )
{
@@ -1470,8 +1486,8 @@ public:
}
else
{
- range -= bound;
code -= bound;
+ range -= bound;
bm.probability -= bm.probability >> bit_model_move_bits;
symbol = 1;
}
@@ -1505,8 +1521,8 @@ public:
unsigned symbol = 1;
for( int i = 7; i >= 0; --i )
{
- const unsigned match_bit = ( match_byte >> i ) & 1;
- const unsigned bit = decode_bit( bm[symbol+(match_bit<<8)+0x100] );
+ const bool match_bit = ( match_byte >> i ) & 1;
+ const bool bit = decode_bit( bm[symbol+(match_bit<<8)+0x100] );
symbol = ( symbol << 1 ) | bit;
if( match_bit != bit )
{
@@ -1521,11 +1537,12 @@ public:
unsigned decode_len( Len_model & lm, const int pos_state )
{
if( decode_bit( lm.choice1 ) == 0 )
- return decode_tree( lm.bm_low[pos_state], len_low_bits );
+ return min_match_len +
+ decode_tree( lm.bm_low[pos_state], len_low_bits );
if( decode_bit( lm.choice2 ) == 0 )
- return len_low_symbols +
+ return min_match_len + len_low_symbols +
decode_tree( lm.bm_mid[pos_state], len_mid_bits );
- return len_low_symbols + len_mid_symbols +
+ return min_match_len + len_low_symbols + len_mid_symbols +
decode_tree( lm.bm_high, len_high_bits );
}
};
@@ -1598,7 +1615,7 @@ void LZ_decoder::flush_data()
}
-bool LZ_decoder::decode_member() // Returns false if error
+bool LZ_decoder::decode_member() // Return false if error
{
Bit_model bm_literal[1<<literal_context_bits][0x300];
Bit_model bm_match[State::states][pos_states];
@@ -1660,12 +1677,12 @@ bool LZ_decoder::decode_member() // Returns false if error
rep0 = distance;
}
state.set_rep();
- len = min_match_len + rdec.decode_len( rep_len_model, pos_state );
+ len = rdec.decode_len( rep_len_model, pos_state );
}
else // match
{
rep3 = rep2; rep2 = rep1; rep1 = rep0;
- len = min_match_len + rdec.decode_len( match_len_model, pos_state );
+ len = rdec.decode_len( match_len_model, pos_state );
const int len_state = std::min( len - min_match_len, len_states - 1 );
rep0 = rdec.decode_tree( bm_dis_slot[len_state], dis_slot_bits );
if( rep0 >= start_dis_model )
@@ -1684,7 +1701,7 @@ bool LZ_decoder::decode_member() // Returns false if error
if( rep0 == 0xFFFFFFFFU ) // marker found
{
flush_data();
- return ( len == min_match_len ); // End Of Stream marker
+ return len == min_match_len; // End Of Stream marker
}
}
}
@@ -1705,11 +1722,11 @@ int main( const int argc, const char * const argv[] )
{
std::printf(
"Lzd %s - Educational decompressor for the lzip format.\n"
- "Study the source to learn how a lzip decompressor works.\n"
+ "Study the source code to learn how a lzip decompressor works.\n"
"See the lzip manual for an explanation of the code.\n"
"\nUsage: %s [-d] < file.lz > file\n"
"Lzd decompresses from standard input to standard output.\n"
- "\nCopyright (C) 2022 Antonio Diaz Diaz.\n"
+ "\nCopyright (C) 2024 Antonio Diaz Diaz.\n"
"License 2-clause BSD.\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"
@@ -1726,8 +1743,8 @@ int main( const int argc, const char * const argv[] )
for( bool first_member = true; ; first_member = false )
{
- Lzip_header header; // verify header
- for( int i = 0; i < 6; ++i ) header[i] = std::getc( stdin );
+ Lzip_header header; // check header
+ for( int i = 0; i < header_size; ++i ) header[i] = std::getc( stdin );
if( std::feof( stdin ) || std::memcmp( header, "LZIP\x01", 5 ) != 0 )
{
if( first_member )
@@ -1745,8 +1762,8 @@ int main( const int argc, const char * const argv[] )
if( !decoder.decode_member() )
{ std::fputs( "Data error\n", stderr ); return 2; }
- Lzip_trailer trailer; // verify trailer
- for( int i = 0; i < 20; ++i ) trailer[i] = decoder.get_byte();
+ Lzip_trailer trailer; // check trailer
+ for( int i = 0; i < trailer_size; ++i ) trailer[i] = decoder.get_byte();
int retval = 0;
unsigned crc = 0;
for( int i = 3; i >= 0; --i ) crc = ( crc << 8 ) + trailer[i];
diff --git a/encoder.cc b/encoder.cc
index afb38d2..11da3a0 100644
--- a/encoder.cc
+++ b/encoder.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
diff --git a/encoder.h b/encoder.h
index 862b524..2654753 100644
--- a/encoder.h
+++ b/encoder.h
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
diff --git a/encoder_base.cc b/encoder_base.cc
index a239d1f..69abd52 100644
--- a/encoder_base.cc
+++ b/encoder_base.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -166,9 +166,8 @@ void LZ_encoder_base::full_flush( const State state )
Lzip_trailer trailer;
trailer.data_crc( crc() );
trailer.data_size( data_position() );
- trailer.member_size( renc.member_position() + Lzip_trailer::size );
- for( int i = 0; i < Lzip_trailer::size; ++i )
- renc.put_byte( trailer.data[i] );
+ trailer.member_size( renc.member_position() + trailer.size );
+ for( int i = 0; i < trailer.size; ++i ) renc.put_byte( trailer.data[i] );
renc.flush_data();
}
diff --git a/encoder_base.h b/encoder_base.h
index b3dd9e6..ef48e0c 100644
--- a/encoder_base.h
+++ b/encoder_base.h
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -86,7 +86,7 @@ inline int price1( const Bit_model bm )
{ return prob_prices[bit_model_total - bm.probability]; }
inline int price_bit( const Bit_model bm, const bool bit )
- { return ( bit ? price1( bm ) : price0( bm ) ); }
+ { return bit ? price1( bm ) : price0( bm ); }
inline int price_symbol3( const Bit_model bm[], int symbol )
@@ -260,8 +260,7 @@ public:
ff_count = 0;
cache = 0;
header.dictionary_size( dictionary_size );
- for( int i = 0; i < Lzip_header::size; ++i )
- put_byte( header.data[i] );
+ for( int i = 0; i < header.size; ++i ) put_byte( header.data[i] );
}
Range_encoder( const unsigned dictionary_size, const int ofd )
diff --git a/fast_encoder.cc b/fast_encoder.cc
index 06d7a05..c6ec497 100644
--- a/fast_encoder.cc
+++ b/fast_encoder.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
diff --git a/fast_encoder.h b/fast_encoder.h
index c41f9e4..e4c97dc 100644
--- a/fast_encoder.h
+++ b/fast_encoder.h
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
diff --git a/list.cc b/list.cc
index befc874..cf68a31 100644
--- a/list.cc
+++ b/list.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -48,12 +48,13 @@ void list_line( const unsigned long long uncomp_size,
int list_files( const std::vector< std::string > & filenames,
- const bool ignore_trailing, const bool loose_trailing )
+ const Cl_options & cl_opts )
{
unsigned long long total_comp = 0, total_uncomp = 0;
int files = 0, retval = 0;
bool first_post = true;
bool stdin_used = false;
+
for( unsigned i = 0; i < filenames.size(); ++i )
{
const bool from_stdin = ( filenames[i] == "-" );
@@ -65,7 +66,7 @@ int list_files( const std::vector< std::string > & filenames,
open_instream( input_filename, &in_stats, false, true );
if( infd < 0 ) { set_retval( retval, 1 ); continue; }
- const Lzip_index lzip_index( infd, ignore_trailing, loose_trailing );
+ const Lzip_index lzip_index( infd, cl_opts );
close( infd );
if( lzip_index.retval() != 0 )
{
diff --git a/lzip.h b/lzip.h
index 186501c..dec033c 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -54,7 +54,7 @@ enum {
dis_slot_bits = 6,
start_dis_model = 4,
end_dis_model = 14,
- modeled_distances = 1 << (end_dis_model / 2), // 128
+ modeled_distances = 1 << ( end_dis_model / 2 ), // 128
dis_align_bits = 4,
dis_align_size = 1 << dis_align_bits,
@@ -187,8 +187,8 @@ extern const CRC32 crc32;
inline bool isvalid_ds( const unsigned dictionary_size )
- { return ( dictionary_size >= min_dictionary_size &&
- dictionary_size <= max_dictionary_size ); }
+ { return dictionary_size >= min_dictionary_size &&
+ dictionary_size <= max_dictionary_size; }
inline int real_bits( unsigned value )
@@ -203,36 +203,35 @@ const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; // "LZIP"
struct Lzip_header
{
- uint8_t data[6]; // 0-3 magic bytes
+ enum { size = 6 };
+ uint8_t data[size]; // 0-3 magic bytes
// 4 version
// 5 coded dictionary size
- enum { size = 6 };
void set_magic() { std::memcpy( data, lzip_magic, 4 ); data[4] = 1; }
- bool verify_magic() const
- { return ( std::memcmp( data, lzip_magic, 4 ) == 0 ); }
+ bool check_magic() const { return std::memcmp( data, lzip_magic, 4 ) == 0; }
- bool verify_prefix( const int sz ) const // detect (truncated) header
+ bool check_prefix( const int sz ) const // detect (truncated) header
{
for( int i = 0; i < sz && i < 4; ++i )
if( data[i] != lzip_magic[i] ) return false;
- return ( sz > 0 );
+ return sz > 0;
}
- bool verify_corrupt() const // detect corrupt header
+ bool check_corrupt() const // detect corrupt header
{
int matches = 0;
for( int i = 0; i < 4; ++i )
if( data[i] == lzip_magic[i] ) ++matches;
- return ( matches > 1 && matches < 4 );
+ return matches > 1 && matches < 4;
}
uint8_t version() const { return data[4]; }
- bool verify_version() const { return ( data[4] == 1 ); }
+ bool check_version() const { return data[4] == 1; }
unsigned dictionary_size() const
{
- unsigned sz = ( 1 << ( data[5] & 0x1F ) );
+ unsigned sz = 1 << ( data[5] & 0x1F );
if( sz > min_dictionary_size )
sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 );
return sz;
@@ -248,23 +247,23 @@ struct Lzip_header
const unsigned fraction = base_size / 16;
for( unsigned i = 7; i >= 1; --i )
if( base_size - ( i * fraction ) >= sz )
- { data[5] |= ( i << 5 ); break; }
+ { data[5] |= i << 5; break; }
}
return true;
}
- bool verify() const
- { return verify_magic() && verify_version() &&
+ bool check() const
+ { return check_magic() && check_version() &&
isvalid_ds( dictionary_size() ); }
};
struct Lzip_trailer
{
- uint8_t data[20]; // 0-3 CRC32 of the uncompressed data
+ enum { size = 20 };
+ uint8_t data[size]; // 0-3 CRC32 of the uncompressed data
// 4-11 size of the uncompressed data
// 12-19 member size including header and trailer
- enum { size = 20 };
unsigned data_crc() const
{
@@ -296,7 +295,7 @@ struct Lzip_trailer
void member_size( unsigned long long sz )
{ for( int i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } }
- bool verify_consistency() const // check internal consistency
+ bool check_consistency() const // check internal consistency
{
const unsigned crc = data_crc();
const unsigned long long dsize = data_size();
@@ -312,6 +311,19 @@ struct Lzip_trailer
};
+struct Cl_options // command-line options
+ {
+ bool ignore_empty;
+ bool ignore_marking;
+ bool ignore_trailing;
+ bool loose_trailing;
+
+ Cl_options()
+ : ignore_empty( true ), ignore_marking( true ),
+ ignore_trailing( true ), loose_trailing( false ) {}
+ };
+
+
struct Error
{
const char * const msg;
@@ -324,6 +336,8 @@ inline void set_retval( int & retval, const int new_val )
const char * const bad_magic_msg = "Bad magic number (file not in lzip format).";
const char * const bad_dict_msg = "Invalid dictionary size in member header.";
const char * const corrupt_mm_msg = "Corrupt header in multimember file.";
+const char * const empty_msg = "Empty member not allowed.";
+const char * const marking_msg = "Marking data not allowed.";
const char * const trailing_msg = "Trailing data not allowed.";
// defined in decoder.cc
@@ -332,7 +346,7 @@ int writeblock( const int fd, const uint8_t * const buf, const int size );
// defined in list.cc
int list_files( const std::vector< std::string > & filenames,
- const bool ignore_trailing, const bool loose_trailing );
+ const Cl_options & cl_opts );
// defined in main.cc
struct stat;
diff --git a/lzip_index.cc b/lzip_index.cc
index b64fb36..6c1caf2 100644
--- a/lzip_index.cc
+++ b/lzip_index.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -43,15 +43,15 @@ int seek_read( const int fd, uint8_t * const buf, const int size,
} // end namespace
-bool Lzip_index::check_header_error( const Lzip_header & header )
+bool Lzip_index::check_header( const Lzip_header & header )
{
- if( !header.verify_magic() )
- { error_ = bad_magic_msg; retval_ = 2; return true; }
- if( !header.verify_version() )
- { error_ = bad_version( header.version() ); retval_ = 2; return true; }
+ if( !header.check_magic() )
+ { error_ = bad_magic_msg; retval_ = 2; return false; }
+ if( !header.check_version() )
+ { error_ = bad_version( header.version() ); retval_ = 2; return false; }
if( !isvalid_ds( header.dictionary_size() ) )
- { error_ = bad_dict_msg; retval_ = 2; return true; }
- return false;
+ { error_ = bad_dict_msg; retval_ = 2; return false; }
+ return true;
}
void Lzip_index::set_errno_error( const char * const msg )
@@ -70,18 +70,20 @@ void Lzip_index::set_num_error( const char * const msg, unsigned long long num )
bool Lzip_index::read_header( const int fd, Lzip_header & header,
- const long long pos )
+ const long long pos, const bool ignore_marking )
{
- if( seek_read( fd, header.data, Lzip_header::size, pos ) != Lzip_header::size )
+ if( seek_read( fd, header.data, header.size, pos ) != header.size )
{ set_errno_error( "Error reading member header: " ); return false; }
+ uint8_t byte;
+ if( !ignore_marking && readblock( fd, &byte, 1 ) == 1 && byte != 0 )
+ { error_ = marking_msg; retval_ = 2; return false; }
return true;
}
// If successful, push last member and set pos to member header.
bool Lzip_index::skip_trailing_data( const int fd, unsigned long long & pos,
- const bool ignore_trailing,
- const bool loose_trailing )
+ const Cl_options & cl_opts )
{
if( pos < min_member_size ) return false;
enum { block_size = 16384,
@@ -102,34 +104,37 @@ bool Lzip_index::skip_trailing_data( const int fd, unsigned long long & pos,
if( buffer[i-1] <= max_msb ) // most significant byte of member_size
{
const Lzip_trailer & trailer =
- *(const Lzip_trailer *)( buffer + i - Lzip_trailer::size );
+ *(const Lzip_trailer *)( buffer + i - trailer.size );
const unsigned long long member_size = trailer.member_size();
if( member_size == 0 ) // skip trailing zeros
- { while( i > Lzip_trailer::size && buffer[i-9] == 0 ) --i; continue; }
- if( member_size > ipos + i || !trailer.verify_consistency() )
- continue;
+ { while( i > trailer.size && buffer[i-9] == 0 ) --i; continue; }
+ if( member_size > ipos + i || !trailer.check_consistency() ) continue;
Lzip_header header;
- if( !read_header( fd, header, ipos + i - member_size ) ) return false;
- if( !header.verify() ) continue;
+ if( !read_header( fd, header, ipos + i - member_size,
+ cl_opts.ignore_marking ) ) return false;
+ if( !header.check() ) continue;
const Lzip_header & header2 = *(const Lzip_header *)( buffer + i );
- const bool full_h2 = bsize - i >= Lzip_header::size;
- if( header2.verify_prefix( bsize - i ) ) // last member
+ const bool full_h2 = bsize - i >= header.size;
+ if( header2.check_prefix( bsize - i ) ) // last member
{
if( !full_h2 ) error_ = "Last member in input file is truncated.";
- else if( !check_header_error( header2 ) )
+ else if( check_header( header2 ) )
error_ = "Last member in input file is truncated or corrupt.";
retval_ = 2; return false;
}
- if( !loose_trailing && full_h2 && header2.verify_corrupt() )
+ if( !cl_opts.loose_trailing && full_h2 && header2.check_corrupt() )
{ error_ = corrupt_mm_msg; retval_ = 2; return false; }
- if( !ignore_trailing )
+ if( !cl_opts.ignore_trailing )
{ error_ = trailing_msg; retval_ = 2; return false; }
- pos = ipos + i - member_size;
+ const unsigned long long data_size = trailer.data_size();
+ if( !cl_opts.ignore_empty && data_size == 0 )
+ { error_ = empty_msg; retval_ = 2; return false; }
+ pos = ipos + i - member_size; // good member
const unsigned dictionary_size = header.dictionary_size();
- member_vector.push_back( Member( 0, trailer.data_size(), pos,
- member_size, dictionary_size ) );
if( dictionary_size_ < dictionary_size )
dictionary_size_ = dictionary_size;
+ member_vector.push_back( Member( 0, data_size, pos, member_size,
+ dictionary_size ) );
return true;
}
if( ipos == 0 )
@@ -144,8 +149,7 @@ bool Lzip_index::skip_trailing_data( const int fd, unsigned long long & pos,
}
-Lzip_index::Lzip_index( const int infd, const bool ignore_trailing,
- const bool loose_trailing )
+Lzip_index::Lzip_index( const int infd, const Cl_options & cl_opts )
: insize( lseek( infd, 0, SEEK_END ) ), retval_( 0 ), dictionary_size_( 0 )
{
if( insize < 0 )
@@ -157,42 +161,42 @@ Lzip_index::Lzip_index( const int infd, const bool ignore_trailing,
retval_ = 2; return; }
Lzip_header header;
- if( !read_header( infd, header, 0 ) ) return;
- if( check_header_error( header ) ) return;
+ if( !read_header( infd, header, 0, cl_opts.ignore_marking ) ||
+ !check_header( header ) ) return;
unsigned long long pos = insize; // always points to a header or to EOF
while( pos >= min_member_size )
{
Lzip_trailer trailer;
- if( seek_read( infd, trailer.data, Lzip_trailer::size,
- pos - Lzip_trailer::size ) != Lzip_trailer::size )
+ if( seek_read( infd, trailer.data, trailer.size, pos - trailer.size ) !=
+ trailer.size )
{ set_errno_error( "Error reading member trailer: " ); break; }
const unsigned long long member_size = trailer.member_size();
- if( member_size > pos || !trailer.verify_consistency() ) // bad trailer
+ if( member_size > pos || !trailer.check_consistency() ) // bad trailer
{
if( member_vector.empty() )
- { if( skip_trailing_data( infd, pos, ignore_trailing, loose_trailing ) )
- continue; else return; }
- set_num_error( "Bad trailer at pos ", pos - Lzip_trailer::size );
- break;
+ { if( skip_trailing_data( infd, pos, cl_opts ) ) continue; return; }
+ set_num_error( "Bad trailer at pos ", pos - trailer.size ); break;
}
- if( !read_header( infd, header, pos - member_size ) ) break;
- if( !header.verify() ) // bad header
+ if( !read_header( infd, header, pos - member_size, cl_opts.ignore_marking ) )
+ break;
+ if( !header.check() ) // bad header
{
if( member_vector.empty() )
- { if( skip_trailing_data( infd, pos, ignore_trailing, loose_trailing ) )
- continue; else return; }
- set_num_error( "Bad header at pos ", pos - member_size );
- break;
+ { if( skip_trailing_data( infd, pos, cl_opts ) ) continue; return; }
+ set_num_error( "Bad header at pos ", pos - member_size ); break;
}
- pos -= member_size;
+ const unsigned long long data_size = trailer.data_size();
+ if( !cl_opts.ignore_empty && data_size == 0 )
+ { error_ = empty_msg; retval_ = 2; break; }
+ pos -= member_size; // good member
const unsigned dictionary_size = header.dictionary_size();
- member_vector.push_back( Member( 0, trailer.data_size(), pos,
- member_size, dictionary_size ) );
if( dictionary_size_ < dictionary_size )
dictionary_size_ = dictionary_size;
+ member_vector.push_back( Member( 0, data_size, pos, member_size,
+ dictionary_size ) );
}
- if( pos != 0 || member_vector.empty() )
+ if( pos != 0 || member_vector.empty() || retval_ != 0 )
{
member_vector.clear();
if( retval_ == 0 ) { error_ = "Can't create file index."; retval_ = 2; }
diff --git a/lzip_index.h b/lzip_index.h
index 442512d..928a7c7 100644
--- a/lzip_index.h
+++ b/lzip_index.h
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -16,13 +16,13 @@
*/
#ifndef INT64_MAX
-#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL
+#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL
#endif
class Block
{
- long long pos_, size_; // pos + size <= INT64_MAX
+ long long pos_, size_; // pos >= 0, size >= 0, pos + size <= INT64_MAX
public:
Block( const long long p, const long long s ) : pos_( p ), size_( s ) {}
@@ -43,9 +43,11 @@ class Lzip_index
Block dblock, mblock; // data block, member block
unsigned dictionary_size;
- Member( const long long dp, const long long ds,
- const long long mp, const long long ms, const unsigned dict_size )
- : dblock( dp, ds ), mblock( mp, ms ), dictionary_size( dict_size ) {}
+ Member( const long long dpos, const long long dsize,
+ const long long mpos, const long long msize,
+ const unsigned dict_size )
+ : dblock( dpos, dsize ), mblock( mpos, msize ),
+ dictionary_size( dict_size ) {}
};
std::vector< Member > member_vector;
@@ -54,16 +56,16 @@ class Lzip_index
int retval_;
unsigned dictionary_size_; // largest dictionary size in the file
- bool check_header_error( const Lzip_header & header );
+ bool check_header( const Lzip_header & header );
void set_errno_error( const char * const msg );
void set_num_error( const char * const msg, unsigned long long num );
- bool read_header( const int fd, Lzip_header & header, const long long pos );
+ bool read_header( const int fd, Lzip_header & header, const long long pos,
+ const bool ignore_marking );
bool skip_trailing_data( const int fd, unsigned long long & pos,
- const bool ignore_trailing, const bool loose_trailing );
+ const Cl_options & cl_opts );
public:
- Lzip_index( const int infd, const bool ignore_trailing,
- const bool loose_trailing );
+ Lzip_index( const int infd, const Cl_options & cl_opts );
long members() const { return member_vector.size(); }
const std::string & error() const { return error_; }
diff --git a/main.cc b/main.cc
index a9d2b47..5db46f2 100644
--- a/main.cc
+++ b/main.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 Antonio Diaz Diaz.
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
@@ -16,9 +16,9 @@
*/
/*
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 invalid input file, 3 for an internal consistency error
- (e.g., bug) which caused lzip to panic.
+ (file not found, invalid command-line options, I/O errors, etc), 2 to
+ indicate a corrupt or invalid input file, 3 for an internal consistency
+ error (e.g., bug) which caused lzip to panic.
*/
#define _FILE_OFFSET_BITS 64
@@ -26,7 +26,7 @@
#include <algorithm>
#include <cctype>
#include <cerrno>
-#include <climits>
+#include <climits> // SSIZE_MAX
#include <csignal>
#include <cstdio>
#include <cstdlib>
@@ -35,7 +35,7 @@
#include <string>
#include <vector>
#include <fcntl.h>
-#include <stdint.h>
+#include <stdint.h> // SIZE_MAX
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
@@ -85,7 +85,7 @@ int verbosity = 0;
namespace {
const char * const program_name = "lzip";
-const char * const program_year = "2022";
+const char * const program_year = "2024";
const char * invocation_name = program_name; // default value
const struct { const char * from; const char * to; } known_extensions[] = {
@@ -112,14 +112,15 @@ void show_help()
{
std::printf( "Lzip is a lossless data compressor with a user interface similar to the one\n"
"of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n"
- "chain-Algorithm' (LZMA) stream format and provides a 3 factor integrity\n"
- "checking to maximize interoperability and optimize safety. Lzip can compress\n"
- "about as fast as gzip (lzip -0) or compress most files more than bzip2\n"
- "(lzip -9). Decompression speed is intermediate between gzip and bzip2.\n"
- "Lzip is better than gzip and bzip2 from a data recovery perspective. Lzip\n"
- "has been designed, written, and tested with great care to replace gzip and\n"
- "bzip2 as the standard general-purpose compressed format for unix-like\n"
- "systems.\n"
+ "chain-Algorithm' (LZMA) stream format to maximize interoperability. The\n"
+ "maximum dictionary size is 512 MiB so that any lzip file can be decompressed\n"
+ "on 32-bit machines. Lzip provides accurate and robust 3-factor integrity\n"
+ "checking. Lzip can compress about as fast as gzip (lzip -0) or compress most\n"
+ "files more than bzip2 (lzip -9). Decompression speed is intermediate between\n"
+ "gzip and bzip2. Lzip is better than gzip and bzip2 from a data recovery\n"
+ "perspective. Lzip has been designed, written, and tested with great care to\n"
+ "replace gzip and bzip2 as the standard general-purpose compressed format for\n"
+ "Unix-like systems.\n"
"\nUsage: %s [options] [files]\n", invocation_name );
std::printf( "\nOptions:\n"
" -h, --help display this help and exit\n"
@@ -127,7 +128,7 @@ void show_help()
" -a, --trailing-error exit with error status if trailing data\n"
" -b, --member-size=<bytes> set member size limit in bytes\n"
" -c, --stdout write to standard output, keep input files\n"
- " -d, --decompress decompress\n"
+ " -d, --decompress decompress, test compressed file integrity\n"
" -f, --force overwrite existing output files\n"
" -F, --recompress force re-compression of compressed files\n"
" -k, --keep keep (don't delete) input files\n"
@@ -142,25 +143,27 @@ void show_help()
" -0 .. -9 set compression level [default 6]\n"
" --fast alias for -0\n"
" --best alias for -9\n"
+ " --empty-error exit with error status if empty member in file\n"
+ " --marking-error exit with error status if 1st LZMA byte not 0\n"
" --loose-trailing allow trailing data seeming corrupt header\n"
"\nIf no file names are given, or if a file is '-', lzip compresses or\n"
"decompresses from standard input to standard output.\n"
"Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n"
"Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n"
- "Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12\n"
- "to 2^29 bytes.\n"
- "\nThe bidimensional parameter space of LZMA can't be mapped to a linear\n"
- "scale optimal for all files. If your files are large, very repetitive,\n"
- "etc, you may need to use the options --dictionary-size and --match-length\n"
- "directly to achieve optimal performance.\n"
+ "Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12 to\n"
+ "2^29 bytes.\n"
+ "\nThe bidimensional parameter space of LZMA can't be mapped to a linear scale\n"
+ "optimal for all files. If your files are large, very repetitive, etc, you\n"
+ "may need to use the options --dictionary-size and --match-length directly\n"
+ "to achieve optimal performance.\n"
"\nTo extract all the files from archive 'foo.tar.lz', use the commands\n"
"'tar -xf foo.tar.lz' or 'lzip -cd foo.tar.lz | tar -xf -'.\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 (e.g., bug) which\n"
- "caused lzip to panic.\n"
+ "\nExit status: 0 for a normal exit, 1 for environmental problems\n"
+ "(file not found, invalid command-line options, I/O errors, etc), 2 to\n"
+ "indicate a corrupt or invalid input file, 3 for an internal consistency\n"
+ "error (e.g., bug) which caused lzip to panic.\n"
"\nThe ideas embodied in lzip are due to (at least) the following people:\n"
- "Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrey Markov (for the\n"
+ "Abraham Lempel and Jacob Ziv (for the LZ algorithm), Andrei Markov (for the\n"
"definition of Markov chains), G.N.N. Martin (for the definition of range\n"
"encoding), Igor Pavlov (for putting all the above together in LZMA), and\n"
"Julian Seward (for bzip2's CLI).\n"
@@ -204,16 +207,15 @@ const char * bad_version( const unsigned version )
const char * format_ds( const unsigned dictionary_size )
{
- enum { bufsize = 16, factor = 1024 };
+ enum { bufsize = 16, factor = 1024, n = 3 };
static char buf[bufsize];
- const char * const prefix[8] =
- { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
+ const char * const prefix[n] = { "Ki", "Mi", "Gi" };
const char * p = "";
const char * np = " ";
unsigned num = dictionary_size;
bool exact = ( num % factor == 0 );
- for( int i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i )
+ for( int i = 0; i < n && ( num > 9999 || ( exact && num >= factor ) ); ++i )
{ num /= factor; if( num % factor != 0 ) exact = false;
p = prefix[i]; np = ""; }
snprintf( buf, bufsize, "%s%4u %sB", np, num, p );
@@ -228,12 +230,12 @@ void show_header( const unsigned dictionary_size )
namespace {
-// separate large numbers >= 100_000 in groups of 3 digits using '_'
+// separate numbers of 5 or more digits in groups of 3 digits using '_'
const char * format_num3( unsigned long long num )
{
- const char * const si_prefix = "kMGTPEZY";
- const char * const binary_prefix = "KMGTPEZY";
- enum { buffers = 8, bufsize = 4 * sizeof (long long) };
+ enum { buffers = 8, bufsize = 4 * sizeof num, n = 10 };
+ const char * const si_prefix = "kMGTPEZYRQ";
+ const char * const binary_prefix = "KMGTPEZYRQ";
static char buffer[buffers][bufsize]; // circle of static buffers for printf
static int current = 0;
@@ -243,15 +245,15 @@ const char * format_num3( unsigned long long num )
if( num > 1024 )
{
char prefix = 0; // try binary first, then si
- for( int i = 0; i < 8 && num >= 1024 && num % 1024 == 0; ++i )
+ for( int i = 0; i < n && num != 0 && num % 1024 == 0; ++i )
{ num /= 1024; prefix = binary_prefix[i]; }
if( prefix ) *(--p) = 'i';
else
- for( int i = 0; i < 8 && num >= 1000 && num % 1000 == 0; ++i )
+ for( int i = 0; i < n && num != 0 && num % 1000 == 0; ++i )
{ num /= 1000; prefix = si_prefix[i]; }
if( prefix ) *(--p) = prefix;
}
- const bool split = num >= 100000;
+ const bool split = num >= 10000;
for( int i = 0; ; )
{
@@ -262,6 +264,16 @@ const char * format_num3( unsigned long long num )
}
+void show_option_error( const char * const arg, const char * const msg,
+ const char * const option_name )
+ {
+ if( verbosity >= 0 )
+ std::fprintf( stderr, "%s: '%s': %s option '%s'.\n",
+ program_name, arg, msg, option_name );
+ }
+
+
+// Recognized formats: <num>k, <num>Ki, <num>[MGTPEZYRQ][i]
unsigned long long getnum( const char * const arg,
const char * const option_name,
const unsigned long long llimit,
@@ -271,12 +283,8 @@ unsigned long long getnum( const char * const arg,
errno = 0;
unsigned long long result = strtoull( arg, &tail, 0 );
if( tail == arg )
- {
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Bad or missing numerical argument in "
- "option '%s'.\n", program_name, option_name );
- std::exit( 1 );
- }
+ { show_option_error( arg, "Bad or missing numerical argument in",
+ option_name ); std::exit( 1 ); }
if( !errno && tail[0] )
{
@@ -284,6 +292,8 @@ unsigned long long getnum( const char * const arg,
int exponent = 0; // 0 = bad multiplier
switch( tail[0] )
{
+ case 'Q': exponent = 10; break;
+ case 'R': exponent = 9; break;
case 'Y': exponent = 8; break;
case 'Z': exponent = 7; break;
case 'E': exponent = 6; break;
@@ -295,12 +305,8 @@ unsigned long long getnum( const char * const arg,
case 'k': if( factor == 1000 ) exponent = 1; break;
}
if( exponent <= 0 )
- {
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Bad multiplier in numerical argument of "
- "option '%s'.\n", program_name, option_name );
- std::exit( 1 );
- }
+ { show_option_error( arg, "Bad multiplier in numerical argument of",
+ option_name ); std::exit( 1 ); }
for( int i = 0; i < exponent; ++i )
{
if( ulimit / factor >= result ) result *= factor;
@@ -311,8 +317,8 @@ unsigned long long getnum( const char * const arg,
if( errno )
{
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Numerical argument out of limits [%s,%s] "
- "in option '%s'.\n", program_name, format_num3( llimit ),
+ std::fprintf( stderr, "%s: '%s': Value out of limits [%s,%s] in "
+ "option '%s'.\n", program_name, arg, format_num3( llimit ),
format_num3( ulimit ), option_name );
std::exit( 1 );
}
@@ -382,7 +388,7 @@ void set_d_outname( const std::string & name, const int eindex )
}
output_filename = name; output_filename += ".out";
if( verbosity >= 1 )
- std::fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'\n",
+ std::fprintf( stderr, "%s: %s: Can't guess original name -- using '%s'\n",
program_name, name.c_str(), output_filename.c_str() );
}
@@ -404,9 +410,9 @@ int open_instream( const char * const name, struct stat * const in_statsp,
if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) )
{
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Input file '%s' is not a regular file%s.\n",
+ std::fprintf( stderr, "%s: %s: Input file is not a regular file%s.\n",
program_name, name, ( can_read && one_to_one ) ?
- ",\n and neither '-c' nor '-o' were specified" : "" );
+ ",\n and neither '-c' nor '-o' were specified" : "" );
close( infd );
infd = -1;
}
@@ -423,7 +429,7 @@ int open_instream2( const char * const name, struct stat * const in_statsp,
if( program_mode == m_compress && !recompress && eindex >= 0 )
{
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Input file '%s' already has '%s' suffix.\n",
+ std::fprintf( stderr, "%s: %s: Input file already has '%s' suffix.\n",
program_name, name, known_extensions[eindex].from );
return -1;
}
@@ -431,6 +437,33 @@ int open_instream2( const char * const name, struct stat * const in_statsp,
}
+bool make_dirs( const std::string & name )
+ {
+ int i = name.size();
+ while( i > 0 && name[i-1] != '/' ) --i; // remove last component
+ while( i > 0 && name[i-1] == '/' ) --i; // remove slash(es)
+ const int dirsize = i; // size of dirname without trailing slash(es)
+
+ for( i = 0; i < dirsize; ) // if dirsize == 0, dirname is '/' or empty
+ {
+ while( i < dirsize && name[i] == '/' ) ++i;
+ const int first = i;
+ while( i < dirsize && name[i] != '/' ) ++i;
+ if( first < i )
+ {
+ const std::string partial( name, 0, i );
+ const mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ struct stat st;
+ if( stat( partial.c_str(), &st ) == 0 )
+ { if( !S_ISDIR( st.st_mode ) ) { errno = ENOTDIR; return false; } }
+ else if( mkdir( partial.c_str(), mode ) != 0 && errno != EEXIST )
+ return false; // if EEXIST, another process created the dir
+ }
+ }
+ return true;
+ }
+
+
bool open_outstream( const bool force, const bool protect )
{
const mode_t usr_rw = S_IRUSR | S_IWUSR;
@@ -439,18 +472,21 @@ bool open_outstream( const bool force, const bool protect )
int flags = O_CREAT | O_WRONLY | O_BINARY;
if( force ) flags |= O_TRUNC; else flags |= O_EXCL;
- outfd = open( output_filename.c_str(), flags, outfd_mode );
- if( outfd >= 0 ) delete_output_on_interrupt = true;
- else if( verbosity >= 0 )
- {
+ outfd = -1;
+ if( output_filename.size() &&
+ output_filename[output_filename.size()-1] == '/' ) errno = EISDIR;
+ else {
+ if( !protect && !make_dirs( output_filename ) )
+ { show_file_error( output_filename.c_str(),
+ "Error creating intermediate directory", errno ); return false; }
+ outfd = open( output_filename.c_str(), flags, outfd_mode );
+ if( outfd >= 0 ) { delete_output_on_interrupt = true; return true; }
if( errno == EEXIST )
- std::fprintf( stderr, "%s: Output file '%s' already exists, skipping.\n",
- program_name, output_filename.c_str() );
- else
- std::fprintf( stderr, "%s: Can't create output file '%s': %s\n",
- program_name, output_filename.c_str(), std::strerror( errno ) );
+ { show_file_error( output_filename.c_str(),
+ "Output file already exists, skipping." ); return false; }
}
- return ( outfd >= 0 );
+ show_file_error( output_filename.c_str(), "Can't create output file", errno );
+ return false;
}
@@ -468,12 +504,11 @@ void cleanup_and_fail( const int retval )
if( delete_output_on_interrupt )
{
delete_output_on_interrupt = false;
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Deleting output file '%s', if it exists.\n",
- program_name, output_filename.c_str() );
+ show_file_error( output_filename.c_str(),
+ "Deleting output file, if it exists." );
if( outfd >= 0 ) { close( outfd ); outfd = -1; }
if( std::remove( output_filename.c_str() ) != 0 && errno != ENOENT )
- show_error( "WARNING: deletion of output file (apparently) failed." );
+ show_error( "warning: deletion of output file failed", errno );
}
std::exit( retval );
}
@@ -517,7 +552,7 @@ void close_and_set_permissions( const struct stat * const in_statsp )
if( in_statsp )
{
const mode_t mode = in_statsp->st_mode;
- // fchown will in many cases return with EPERM, which can be safely ignored.
+ // fchown in many cases returns with EPERM, which can be safely ignored.
if( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) == 0 )
{ if( fchmod( outfd, mode ) != 0 ) warning = true; }
else
@@ -526,10 +561,8 @@ void close_and_set_permissions( const struct stat * const in_statsp )
warning = true;
}
if( close( outfd ) != 0 )
- {
- show_error( "Error closing output file", errno );
- cleanup_and_fail( 1 );
- }
+ { show_file_error( output_filename.c_str(), "Error closing output file",
+ errno ); cleanup_and_fail( 1 ); }
outfd = -1;
delete_output_on_interrupt = false;
if( in_statsp )
@@ -540,7 +573,8 @@ void close_and_set_permissions( const struct stat * const in_statsp )
if( utime( output_filename.c_str(), &t ) != 0 ) warning = true;
}
if( warning && verbosity >= 1 )
- show_error( "Can't change output file attributes." );
+ show_file_error( output_filename.c_str(),
+ "warning: can't change output file attributes", errno );
}
@@ -627,7 +661,7 @@ int compress( const unsigned long long cfile_size,
}
-unsigned char xdigit( const unsigned value )
+unsigned char xdigit( const unsigned value ) // hex digit for 'value'
{
if( value <= 9 ) return '0' + value;
if( value <= 15 ) return 'A' + value - 10;
@@ -657,13 +691,13 @@ bool show_trailing_data( const uint8_t * const data, const int size,
pp( msg.c_str() );
if( ignore_trailing == 0 ) show_file_error( pp.name(), trailing_msg );
}
- return ( ignore_trailing > 0 );
+ return ignore_trailing > 0;
}
int decompress( const unsigned long long cfile_size, const int infd,
- const Pretty_print & pp, const bool ignore_trailing,
- const bool loose_trailing, const bool testing )
+ const Cl_options & cl_opts, const Pretty_print & pp,
+ const bool testing )
{
unsigned long long partial_file_pos = 0;
Range_decoder rdec( infd );
@@ -673,34 +707,31 @@ int decompress( const unsigned long long cfile_size, const int infd,
{
Lzip_header header;
rdec.reset_member_position();
- const int size = rdec.read_data( header.data, Lzip_header::size );
+ const int size = rdec.read_data( header.data, header.size );
if( rdec.finished() ) // End Of File
{
if( first_member )
{ show_file_error( pp.name(), "File ends unexpectedly at member header." );
retval = 2; }
- else if( header.verify_prefix( size ) )
+ else if( header.check_prefix( size ) )
{ pp( "Truncated header in multimember file." );
- show_trailing_data( header.data, size, pp, true, -1 );
- retval = 2; }
- else if( size > 0 && !show_trailing_data( header.data, size, pp,
- true, ignore_trailing ) )
- retval = 2;
+ show_trailing_data( header.data, size, pp, true, -1 ); retval = 2; }
+ else if( size > 0 && !show_trailing_data( header.data, size, pp, true,
+ cl_opts.ignore_trailing ) ) retval = 2;
break;
}
- if( !header.verify_magic() )
+ if( !header.check_magic() )
{
if( first_member )
{ show_file_error( pp.name(), bad_magic_msg ); retval = 2; }
- else if( !loose_trailing && header.verify_corrupt() )
+ else if( !cl_opts.loose_trailing && header.check_corrupt() )
{ pp( corrupt_mm_msg );
- show_trailing_data( header.data, size, pp, false, -1 );
- retval = 2; }
- else if( !show_trailing_data( header.data, size, pp, false, ignore_trailing ) )
- retval = 2;
+ show_trailing_data( header.data, size, pp, false, -1 ); retval = 2; }
+ else if( !show_trailing_data( header.data, size, pp, false,
+ cl_opts.ignore_trailing ) ) retval = 2;
break;
}
- if( !header.verify_version() )
+ if( !header.check_version() )
{ pp( bad_version( header.version() ) ); retval = 2; break; }
const unsigned dictionary_size = header.dictionary_size();
if( !isvalid_ds( dictionary_size ) )
@@ -710,7 +741,7 @@ int decompress( const unsigned long long cfile_size, const int infd,
LZ_decoder decoder( rdec, dictionary_size, outfd );
show_dprogress( cfile_size, partial_file_pos, &rdec, &pp ); // init
- const int result = decoder.decode_member( pp );
+ const int result = decoder.decode_member( cl_opts, pp );
partial_file_pos += rdec.member_position();
if( result != 0 )
{
@@ -721,6 +752,8 @@ int decompress( const unsigned long long cfile_size, const int infd,
"File ends unexpectedly" : "Decoder error",
partial_file_pos );
}
+ else if( result == 5 ) pp( empty_msg );
+ else if( result == 6 ) pp( marking_msg );
retval = 2; break;
}
if( verbosity >= 2 )
@@ -827,8 +860,8 @@ void show_dprogress( const unsigned long long cfile_size,
int main( const int argc, const char * const argv[] )
{
- /* Mapping from gzip/bzip2 style 1..9 compression modes
- to the corresponding LZMA compression modes. */
+ /* Mapping from gzip/bzip2 style 0..9 compression levels to the
+ corresponding LZMA compression parameters. */
const Lzma_options option_mapping[] =
{
{ 1 << 16, 16 }, // -0
@@ -842,54 +875,55 @@ int main( const int argc, const char * const argv[] )
{ 3 << 23, 132 }, // -8
{ 1 << 25, 273 } }; // -9
Lzma_options encoder_options = option_mapping[6]; // default = "-6"
- const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */
- const unsigned long long max_volume_size = 0x4000000000000000ULL; /* 4 EiB */
+ const unsigned long long max_member_size = 0x0008000000000000ULL; // 2 PiB
+ const unsigned long long max_volume_size = 0x4000000000000000ULL; // 4 EiB
unsigned long long member_size = max_member_size;
unsigned long long volume_size = 0;
std::string default_output_filename;
Mode program_mode = m_compress;
+ Cl_options cl_opts; // command-line options
bool force = false;
- bool ignore_trailing = true;
bool keep_input_files = false;
- bool loose_trailing = false;
bool recompress = false;
bool to_stdout = false;
bool zero = false;
if( argc > 0 ) invocation_name = argv[0];
- enum { opt_lt = 256 };
+ enum { opt_eer = 256, opt_lt, opt_mer };
const Arg_parser::Option options[] =
{
- { '0', "fast", 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', "best", Arg_parser::no },
- { 'a', "trailing-error", Arg_parser::no },
- { 'b', "member-size", Arg_parser::yes },
- { 'c', "stdout", Arg_parser::no },
- { 'd', "decompress", Arg_parser::no },
- { 'f', "force", Arg_parser::no },
- { 'F', "recompress", Arg_parser::no },
- { 'h', "help", Arg_parser::no },
- { 'k', "keep", Arg_parser::no },
- { 'l', "list", Arg_parser::no },
- { 'm', "match-length", Arg_parser::yes },
- { 'n', "threads", Arg_parser::yes },
- { 'o', "output", Arg_parser::yes },
- { 'q', "quiet", Arg_parser::no },
- { 's', "dictionary-size", Arg_parser::yes },
- { 'S', "volume-size", Arg_parser::yes },
- { 't', "test", Arg_parser::no },
- { 'v', "verbose", Arg_parser::no },
- { 'V', "version", Arg_parser::no },
- { opt_lt, "loose-trailing", Arg_parser::no },
- { 0, 0, Arg_parser::no } };
+ { '0', "fast", 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', "best", Arg_parser::no },
+ { 'a', "trailing-error", Arg_parser::no },
+ { 'b', "member-size", Arg_parser::yes },
+ { 'c', "stdout", Arg_parser::no },
+ { 'd', "decompress", Arg_parser::no },
+ { 'f', "force", Arg_parser::no },
+ { 'F', "recompress", Arg_parser::no },
+ { 'h', "help", Arg_parser::no },
+ { 'k', "keep", Arg_parser::no },
+ { 'l', "list", Arg_parser::no },
+ { 'm', "match-length", Arg_parser::yes },
+ { 'n', "threads", Arg_parser::yes },
+ { 'o', "output", Arg_parser::yes },
+ { 'q', "quiet", Arg_parser::no },
+ { 's', "dictionary-size", Arg_parser::yes },
+ { 'S', "volume-size", Arg_parser::yes },
+ { 't', "test", Arg_parser::no },
+ { 'v', "verbose", Arg_parser::no },
+ { 'V', "version", Arg_parser::no },
+ { opt_eer, "empty-error", Arg_parser::no },
+ { opt_lt, "loose-trailing", Arg_parser::no },
+ { opt_mer, "marking-error", Arg_parser::no },
+ { 0, 0, Arg_parser::no } };
const Arg_parser parser( argc, argv, options );
if( parser.error().size() ) // bad option
@@ -909,7 +943,7 @@ int main( const int argc, const char * const argv[] )
case '5': case '6': case '7': case '8': case '9':
zero = ( code == '0' );
encoder_options = option_mapping[code-'0']; break;
- case 'a': ignore_trailing = false; break;
+ case 'a': cl_opts.ignore_trailing = false; break;
case 'b': member_size = getnum( arg, pn, 100000, max_member_size ); break;
case 'c': to_stdout = true; break;
case 'd': set_mode( program_mode, m_decompress ); break;
@@ -931,8 +965,10 @@ int main( const int argc, const char * const argv[] )
case 't': set_mode( program_mode, m_test ); break;
case 'v': if( verbosity < 4 ) ++verbosity; break;
case 'V': show_version(); return 0;
- case opt_lt: loose_trailing = true; break;
- default : internal_error( "uncaught option." );
+ case opt_eer: cl_opts.ignore_empty = false; break;
+ case opt_lt: cl_opts.loose_trailing = true; break;
+ case opt_mer: cl_opts.ignore_marking = false; break;
+ default: internal_error( "uncaught option." );
}
} // end process options
@@ -950,8 +986,7 @@ int main( const int argc, const char * const argv[] )
}
if( filenames.empty() ) filenames.push_back("-");
- if( program_mode == m_list )
- return list_files( filenames, ignore_trailing, loose_trailing );
+ if( program_mode == m_list ) return list_files( filenames, cl_opts );
if( program_mode == m_compress )
{
@@ -981,11 +1016,11 @@ int main( const int argc, const char * const argv[] )
int retval = 0;
const bool one_to_one = !to_stdout && program_mode != m_test && !to_file;
bool stdin_used = false;
+ struct stat in_stats;
for( unsigned i = 0; i < filenames.size(); ++i )
{
std::string input_filename;
int infd;
- struct stat in_stats;
pp.set_name( filenames[i] );
if( filenames[i] == "-" )
@@ -1002,7 +1037,7 @@ int main( const int argc, const char * const argv[] )
eindex, one_to_one, recompress );
if( infd < 0 ) { set_retval( retval, 1 ); continue; }
if( !check_tty_in( pp.name(), infd, program_mode, retval ) ) continue;
- if( one_to_one ) // open outfd after verifying infd
+ if( one_to_one ) // open outfd after checking infd
{
if( program_mode == m_compress )
set_c_outname( input_filename, true, true, volume_size > 0 );
@@ -1015,7 +1050,7 @@ int main( const int argc, const char * const argv[] )
if( one_to_one && !check_tty_out( program_mode ) )
{ set_retval( retval, 1 ); return retval; } // don't delete a tty
- if( to_file && outfd < 0 ) // open outfd after verifying infd
+ if( to_file && outfd < 0 ) // open outfd after checking infd
{
if( program_mode == m_compress ) set_c_outname( default_output_filename,
filenames_given, false, volume_size > 0 );
@@ -1035,8 +1070,7 @@ int main( const int argc, const char * const argv[] )
tmp = compress( cfile_size, member_size, volume_size, infd,
encoder_options, pp, in_statsp, zero );
else
- tmp = decompress( cfile_size, infd, pp, ignore_trailing,
- loose_trailing, program_mode == m_test );
+ tmp = decompress( cfile_size, infd, cl_opts, pp, program_mode == m_test );
}
catch( std::bad_alloc & )
{ pp( ( program_mode == m_compress ) ?
@@ -1057,7 +1091,9 @@ int main( const int argc, const char * const argv[] )
( program_mode != m_compress || volume_size == 0 ) )
std::remove( input_filename.c_str() );
}
- if( delete_output_on_interrupt ) close_and_set_permissions( 0 ); // -o
+ if( delete_output_on_interrupt ) // -o
+ close_and_set_permissions( ( retval == 0 && !stdin_used &&
+ filenames_given && filenames.size() == 1 ) ? &in_stats : 0 );
else if( outfd >= 0 && close( outfd ) != 0 ) // -c
{
show_error( "Error closing stdout", errno );
diff --git a/testsuite/check.sh b/testsuite/check.sh
index 916ed4e..dd9a60a 100755
--- a/testsuite/check.sh
+++ b/testsuite/check.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# check script for Lzip - LZMA lossless data compressor
-# Copyright (C) 2008-2022 Antonio Diaz Diaz.
+# Copyright (C) 2008-2024 Antonio Diaz Diaz.
#
# This script is free software: you have unlimited permission
# to copy, distribute, and modify it.
@@ -32,6 +32,8 @@ cat "${testdir}"/test.txt > in || framework_failure
in_lz="${testdir}"/test.txt.lz
in_em="${testdir}"/test_em.txt.lz
fox_lz="${testdir}"/fox.lz
+fox6_lz="${testdir}"/fox6.lz
+f6mk_lz="${testdir}"/fox6_mark.lz
fail=0
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
@@ -70,12 +72,13 @@ done
[ ! -e out.lz ] || test_failed $LINENO
"${LZIP}" -qf -S100k -o out in in
[ $? = 1 ] || test_failed $LINENO
+{ [ ! -e out ] && [ ! -e out.lz ] ; } || test_failed $LINENO
# these are for code coverage
"${LZIP}" -lt "${in_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
-"${LZIP}" -cdl "${in_lz}" > out 2> /dev/null
+"${LZIP}" -cdl "${in_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
-"${LZIP}" -cdt "${in_lz}" > out 2> /dev/null
+"${LZIP}" -cdt "${in_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
"${LZIP}" -t -- nx_file.lz 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
@@ -100,39 +103,43 @@ done
printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null
printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null
printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null
-rm -f out || framework_failure
printf "\ntesting decompression..."
for i in "${in_lz}" "${in_em}" ; do
"${LZIP}" -lq "$i" || test_failed $LINENO "$i"
"${LZIP}" -t "$i" || test_failed $LINENO "$i"
- "${LZIP}" -d "$i" -o copy || test_failed $LINENO "$i"
- cmp in copy || test_failed $LINENO "$i"
- "${LZIP}" -cd "$i" > copy || test_failed $LINENO "$i"
- cmp in copy || test_failed $LINENO "$i"
- "${LZIP}" -d "$i" -o - > copy || test_failed $LINENO "$i"
- cmp in copy || test_failed $LINENO "$i"
- "${LZIP}" -d < "$i" > copy || test_failed $LINENO "$i"
- cmp in copy || test_failed $LINENO "$i"
- rm -f copy || framework_failure
+ "${LZIP}" -d "$i" -o out || test_failed $LINENO "$i"
+ cmp in out || test_failed $LINENO "$i"
+ "${LZIP}" -cd "$i" > out || test_failed $LINENO "$i"
+ cmp in out || test_failed $LINENO "$i"
+ "${LZIP}" -d "$i" -o - > out || test_failed $LINENO "$i"
+ cmp in out || test_failed $LINENO "$i"
+ "${LZIP}" -d < "$i" > out || test_failed $LINENO "$i"
+ cmp in out || test_failed $LINENO "$i"
+ rm -f out || framework_failure
done
-lines=$("${LZIP}" -tvv "${in_em}" 2>&1 | wc -l) || test_failed $LINENO
+lines=`"${LZIP}" -tvv "${in_em}" 2>&1 | wc -l` || test_failed $LINENO
[ "${lines}" -eq 8 ] || test_failed $LINENO "${lines}"
+"${LZIP}" -tq "${in_em}" --empty-error
+[ $? = 2 ] || test_failed $LINENO
-lines=$("${LZIP}" -lvv "${in_em}" | wc -l) || test_failed $LINENO
+lines=`"${LZIP}" -lvv "${in_em}" | wc -l` || test_failed $LINENO
[ "${lines}" -eq 11 ] || test_failed $LINENO "${lines}"
+"${LZIP}" -lq "${in_em}" --empty-error
+[ $? = 2 ] || test_failed $LINENO
-"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO
-cat "${in_lz}" > copy.lz || framework_failure
-"${LZIP}" -dk copy.lz || test_failed $LINENO
-cmp in copy || test_failed $LINENO
-cat fox > copy || framework_failure
cat "${in_lz}" > out.lz || framework_failure
+"${LZIP}" -dk out.lz || test_failed $LINENO
+cmp in out || test_failed $LINENO
rm -f out || framework_failure
+"${LZIP}" -cd "${fox_lz}" > fox || test_failed $LINENO
+cat fox > copy || framework_failure
+cat "${in_lz}" > copy.lz || framework_failure
"${LZIP}" -d copy.lz out.lz 2> /dev/null # skip copy, decompress out
[ $? = 1 ] || test_failed $LINENO
+[ ! -e out.lz ] || test_failed $LINENO
cmp fox copy || test_failed $LINENO
cmp in out || test_failed $LINENO
"${LZIP}" -df copy.lz || test_failed $LINENO
@@ -140,15 +147,15 @@ cmp in out || test_failed $LINENO
cmp in copy || test_failed $LINENO
rm -f copy out || framework_failure
-cat "${in_lz}" > copy.lz || framework_failure
-"${LZIP}" -d -S100k copy.lz || test_failed $LINENO # ignore -S
-[ ! -e copy.lz ] || test_failed $LINENO
-cmp in copy || test_failed $LINENO
+cat "${in_lz}" > out.lz || framework_failure
+"${LZIP}" -d -S100k out.lz || test_failed $LINENO # ignore -S
+[ ! -e out.lz ] || test_failed $LINENO
+cmp in out || test_failed $LINENO
-printf "to be overwritten" > copy || framework_failure
-"${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO
-cmp in copy || test_failed $LINENO
-rm -f out copy || framework_failure
+printf "to be overwritten" > out || framework_failure
+"${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO
+cmp in out || test_failed $LINENO
+rm -f out || framework_failure
"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO
cmp in ./- || test_failed $LINENO
rm -f ./- || framework_failure
@@ -157,11 +164,11 @@ cmp in ./- || test_failed $LINENO
rm -f ./- || framework_failure
cat "${in_lz}" > anyothername || framework_failure
-"${LZIP}" -dv - anyothername - < "${in_lz}" > copy 2> /dev/null ||
+"${LZIP}" -dv - anyothername - < "${in_lz}" > out 2> /dev/null ||
test_failed $LINENO
-cmp in copy || test_failed $LINENO
+cmp in out || test_failed $LINENO
cmp in anyothername.out || test_failed $LINENO
-rm -f copy anyothername.out || framework_failure
+rm -f out anyothername.out || framework_failure
"${LZIP}" -lq in "${in_lz}"
[ $? = 2 ] || test_failed $LINENO
@@ -171,62 +178,82 @@ rm -f copy anyothername.out || framework_failure
[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -tq nx_file.lz "${in_lz}"
[ $? = 1 ] || test_failed $LINENO
-"${LZIP}" -cdq in "${in_lz}" > copy
+"${LZIP}" -cdq in "${in_lz}" > out
[ $? = 2 ] || test_failed $LINENO
-cat copy in | cmp in - || test_failed $LINENO # copy must be empty
-"${LZIP}" -cdq nx_file.lz "${in_lz}" > copy
+cat out in | cmp in - || test_failed $LINENO # out must be empty
+"${LZIP}" -cdq nx_file.lz "${in_lz}" > out # skip nx_file, decompress in
[ $? = 1 ] || test_failed $LINENO
-cmp in copy || test_failed $LINENO
-rm -f copy || framework_failure
-cat "${in_lz}" > copy.lz || framework_failure
+cmp in out || test_failed $LINENO
+rm -f out || framework_failure
+cat "${in_lz}" > out.lz || framework_failure
for i in 1 2 3 4 5 6 7 ; do
- printf "g" >> copy.lz || framework_failure
- "${LZIP}" -alvv copy.lz "${in_lz}" > /dev/null 2>&1
+ printf "g" >> out.lz || framework_failure
+ "${LZIP}" -alvv out.lz "${in_lz}" > /dev/null 2>&1
[ $? = 2 ] || test_failed $LINENO $i
- "${LZIP}" -atvvvv copy.lz "${in_lz}" 2> /dev/null
+ "${LZIP}" -atvvvv out.lz "${in_lz}" 2> /dev/null
[ $? = 2 ] || test_failed $LINENO $i
done
-"${LZIP}" -dq in copy.lz
+"${LZIP}" -dq in out.lz
[ $? = 2 ] || test_failed $LINENO
-[ -e copy.lz ] || test_failed $LINENO
-[ ! -e copy ] || test_failed $LINENO
+[ -e out.lz ] || test_failed $LINENO
+[ ! -e out ] || test_failed $LINENO
[ ! -e in.out ] || test_failed $LINENO
-"${LZIP}" -dq nx_file.lz copy.lz
+"${LZIP}" -dq nx_file.lz out.lz
[ $? = 1 ] || test_failed $LINENO
-[ ! -e copy.lz ] || test_failed $LINENO
+[ ! -e out.lz ] || test_failed $LINENO
[ ! -e nx_file ] || test_failed $LINENO
-cmp in copy || test_failed $LINENO
+cmp in out || test_failed $LINENO
+rm -f out || framework_failure
cat in in > in2 || framework_failure
"${LZIP}" -lq "${in_lz}" "${in_lz}" || test_failed $LINENO
"${LZIP}" -t "${in_lz}" "${in_lz}" || test_failed $LINENO
-"${LZIP}" -cd "${in_lz}" "${in_lz}" -o out > copy2 || test_failed $LINENO
+"${LZIP}" -cd "${in_lz}" "${in_lz}" -o out > out2 || test_failed $LINENO
[ ! -e out ] || test_failed $LINENO # override -o
-cmp in2 copy2 || test_failed $LINENO
-rm -f copy2 || framework_failure
-"${LZIP}" -d "${in_lz}" "${in_lz}" -o copy2 || test_failed $LINENO
-cmp in2 copy2 || test_failed $LINENO
-rm -f copy2 || framework_failure
-
-cat "${in_lz}" "${in_lz}" > copy2.lz || framework_failure
-printf "\ngarbage" >> copy2.lz || framework_failure
-"${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO
-"${LZIP}" -alq copy2.lz
+cmp in2 out2 || test_failed $LINENO
+rm -f out2 || framework_failure
+"${LZIP}" -d "${in_lz}" "${in_lz}" -o out2 || test_failed $LINENO
+cmp in2 out2 || test_failed $LINENO
+rm -f out2 || framework_failure
+
+cat "${in_lz}" "${in_lz}" > out2.lz || framework_failure
+printf "\ngarbage" >> out2.lz || framework_failure
+"${LZIP}" -tvvvv out2.lz 2> /dev/null || test_failed $LINENO
+"${LZIP}" -alq out2.lz
+[ $? = 2 ] || test_failed $LINENO
+"${LZIP}" -atq out2.lz
+[ $? = 2 ] || test_failed $LINENO
+"${LZIP}" -atq < out2.lz
[ $? = 2 ] || test_failed $LINENO
-"${LZIP}" -atq copy2.lz
+"${LZIP}" -adkq out2.lz
[ $? = 2 ] || test_failed $LINENO
-"${LZIP}" -atq < copy2.lz
+[ ! -e out2 ] || test_failed $LINENO
+"${LZIP}" -adkq -o out2 < out2.lz
[ $? = 2 ] || test_failed $LINENO
-"${LZIP}" -adkq copy2.lz
+[ ! -e out2 ] || test_failed $LINENO
+printf "to be overwritten" > out2 || framework_failure
+"${LZIP}" -df out2.lz || test_failed $LINENO
+cmp in2 out2 || test_failed $LINENO
+rm -f out2 || framework_failure
+
+"${LZIP}" -cd "${fox6_lz}" > out || test_failed $LINENO
+"${LZIP}" -cd "${f6mk_lz}" > copy || test_failed $LINENO
+cmp copy out || test_failed $LINENO
+rm -f copy out || framework_failure
+"${LZIP}" -lq "${f6mk_lz}" --marking-error
[ $? = 2 ] || test_failed $LINENO
-[ ! -e copy2 ] || test_failed $LINENO
-"${LZIP}" -adkq -o copy2 < copy2.lz
+"${LZIP}" -tq "${f6mk_lz}" --marking-error
[ $? = 2 ] || test_failed $LINENO
-[ ! -e copy2 ] || test_failed $LINENO
-printf "to be overwritten" > copy2 || framework_failure
-"${LZIP}" -df copy2.lz || test_failed $LINENO
-cmp in2 copy2 || test_failed $LINENO
-rm -f copy2 || framework_failure
+
+"${LZIP}" -d "${fox_lz}" -o a/b/c/fox || test_failed $LINENO
+cmp fox a/b/c/fox || test_failed $LINENO
+rm -rf a || framework_failure
+"${LZIP}" -d -o a/b/c/fox < "${fox_lz}" || test_failed $LINENO
+cmp fox a/b/c/fox || test_failed $LINENO
+rm -rf a || framework_failure
+"${LZIP}" -dq "${fox_lz}" -o a/b/c/
+[ $? = 1 ] || test_failed $LINENO
+[ ! -e a ] || test_failed $LINENO
printf "\ntesting compression..."
@@ -234,14 +261,16 @@ printf "\ntesting compression..."
[ ! -e out3.lz ] || test_failed $LINENO # override -o and -S
"${LZIP}" -0f in in --output=copy2.lz || test_failed $LINENO
"${LZIP}" -d copy2.lz -o out2 || test_failed $LINENO
+[ -e copy2.lz ] || test_failed $LINENO
cmp in2 out2 || test_failed $LINENO
rm -f in2 out2 copy2.lz || framework_failure
-"${LZIP}" -cf "${in_lz}" > out 2> /dev/null # /dev/null is a tty on OS/2
+"${LZIP}" -cf "${in_lz}" > lzlz 2> /dev/null # /dev/null is a tty on OS/2
[ $? = 1 ] || test_failed $LINENO
-"${LZIP}" -Fvvm36 -o - "${in_lz}" > out 2> /dev/null || test_failed $LINENO
-"${LZIP}" -cd out | "${LZIP}" -d > copy || test_failed $LINENO
-cmp in copy || test_failed $LINENO
+"${LZIP}" -Fvvm36 -o - "${in_lz}" > lzlz 2> /dev/null || test_failed $LINENO
+"${LZIP}" -cd lzlz | "${LZIP}" -d > out || test_failed $LINENO
+cmp in out || test_failed $LINENO
+rm -f lzlz out || framework_failure
"${LZIP}" -0 -o ./- in || test_failed $LINENO
"${LZIP}" -cd ./- | cmp in - || test_failed $LINENO
@@ -253,10 +282,10 @@ rm -f ./-.lz || framework_failure
for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
"${LZIP}" -k -$i in || test_failed $LINENO $i
- mv -f in.lz copy.lz || test_failed $LINENO $i
- printf "garbage" >> copy.lz || framework_failure
- "${LZIP}" -df copy.lz || test_failed $LINENO $i
- cmp in copy || test_failed $LINENO $i
+ mv in.lz out.lz || test_failed $LINENO $i
+ printf "garbage" >> out.lz || framework_failure
+ "${LZIP}" -df out.lz || test_failed $LINENO $i
+ cmp in out || test_failed $LINENO $i
"${LZIP}" -$i in -c > out || test_failed $LINENO $i
"${LZIP}" -$i in -o o_out || test_failed $LINENO $i # don't add .lz
@@ -278,7 +307,7 @@ for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
"${LZIP}" -df -o copy < out.lz || test_failed $LINENO $i
cmp in copy || test_failed $LINENO $i
done
-rm -f out out.lz || framework_failure
+rm -f copy out.lz || framework_failure
cat in in in in in in in in > in8 || framework_failure
"${LZIP}" -1s12 -S100k in8 || test_failed $LINENO
@@ -303,11 +332,12 @@ rm -f in8 || framework_failure
"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO
[ ! -e out00003.lz ] || test_failed $LINENO
rm -f out00001.lz || framework_failure
-"${LZIP}" -1 -S100k -o out < in8.lz || test_failed $LINENO
-"${LZIP}" -t out00001.lz out00002.lz || test_failed $LINENO
-"${LZIP}" -cd out00001.lz out00002.lz | cmp in8.lz - || test_failed $LINENO
-[ ! -e out00003.lz ] || test_failed $LINENO
-rm -f out00001.lz out00002.lz || framework_failure
+"${LZIP}" -1 -S100k -o a/b/c/out < in8.lz || test_failed $LINENO
+"${LZIP}" -t a/b/c/out00001.lz a/b/c/out00002.lz || test_failed $LINENO
+"${LZIP}" -cd a/b/c/out00001.lz a/b/c/out00002.lz | cmp in8.lz - ||
+ test_failed $LINENO
+[ ! -e a/b/c/out00003.lz ] || test_failed $LINENO
+rm -rf a || framework_failure
"${LZIP}" -0 -F -S100k in8.lz || test_failed $LINENO
"${LZIP}" -t in8.lz00001.lz in8.lz00002.lz || test_failed $LINENO
"${LZIP}" -cd in8.lz00001.lz in8.lz00002.lz | cmp in8.lz - || test_failed $LINENO
@@ -318,16 +348,23 @@ rm -f in8.lz00001.lz in8.lz00002.lz || framework_failure
"${LZIP}" -cd in8.lz.lz | cmp in8.lz - || test_failed $LINENO
rm -f in8.lz in8.lz.lz || framework_failure
+"${LZIP}" fox -o a/b/c/fox.lz || test_failed $LINENO
+cmp "${fox_lz}" a/b/c/fox.lz || test_failed $LINENO
+rm -rf a || framework_failure
+"${LZIP}" -o a/b/c/fox.lz < fox || test_failed $LINENO
+cmp "${fox_lz}" a/b/c/fox.lz || test_failed $LINENO
+rm -rf a || framework_failure
+
printf "\ntesting bad input..."
headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP'
body='\001\014\000\203\377\373\377\377\300\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000$\000\000\000\000\000\000\000'
-cat "${in_lz}" > int.lz
-printf "LZIP${body}" >> int.lz
+cat "${in_lz}" > int.lz || framework_failure
+printf "LZIP${body}" >> int.lz || framework_failure
if "${LZIP}" -tq int.lz ; then
for header in ${headers} ; do
- printf "${header}${body}" > int.lz # first member
- "${LZIP}" -lq int.lz
+ printf "${header}${body}" > int.lz || framework_failure
+ "${LZIP}" -lq int.lz # first member
[ $? = 2 ] || test_failed $LINENO ${header}
"${LZIP}" -tq int.lz
[ $? = 2 ] || test_failed $LINENO ${header}
@@ -343,9 +380,9 @@ if "${LZIP}" -tq int.lz ; then
[ $? = 2 ] || test_failed $LINENO ${header}
"${LZIP}" -cdq --loose-trailing int.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO ${header}
- cat "${in_lz}" > int.lz
- printf "${header}${body}" >> int.lz # trailing data
- "${LZIP}" -lq int.lz
+ cat "${in_lz}" > int.lz || framework_failure
+ printf "${header}${body}" >> int.lz || framework_failure
+ "${LZIP}" -lq int.lz # trailing data
[ $? = 2 ] || test_failed $LINENO ${header}
"${LZIP}" -tq int.lz
[ $? = 2 ] || test_failed $LINENO ${header}
@@ -400,15 +437,15 @@ if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null &&
[ $? = 2 ] || test_failed $LINENO $i
"${LZIP}" -tq < trunc.lz
[ $? = 2 ] || test_failed $LINENO $i
- "${LZIP}" -cdq trunc.lz > out
+ "${LZIP}" -cdq trunc.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO $i
- "${LZIP}" -dq < trunc.lz > out
+ "${LZIP}" -dq < trunc.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO $i
done
else
printf "\nwarning: skipping truncation test: 'dd' does not work on your system."
fi
-rm -f in2.lz in3.lz trunc.lz out || framework_failure
+rm -f in2.lz in3.lz trunc.lz || framework_failure
cat "${in_lz}" > ingin.lz || framework_failure
printf "g" >> ingin.lz || framework_failure
@@ -419,17 +456,17 @@ cat "${in_lz}" >> ingin.lz || framework_failure
[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -atq < ingin.lz
[ $? = 2 ] || test_failed $LINENO
-"${LZIP}" -acdq ingin.lz > out
+"${LZIP}" -acdq ingin.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO
-"${LZIP}" -adq < ingin.lz > out
+"${LZIP}" -adq < ingin.lz > /dev/null
[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -t ingin.lz || test_failed $LINENO
"${LZIP}" -t < ingin.lz || test_failed $LINENO
-"${LZIP}" -cd ingin.lz > copy || test_failed $LINENO
-cmp in copy || test_failed $LINENO
-"${LZIP}" -d < ingin.lz > copy || test_failed $LINENO
-cmp in copy || test_failed $LINENO
-rm -f copy ingin.lz out || framework_failure
+"${LZIP}" -cd ingin.lz > out || test_failed $LINENO
+cmp in out || test_failed $LINENO
+"${LZIP}" -d < ingin.lz > out || test_failed $LINENO
+cmp in out || test_failed $LINENO
+rm -f out ingin.lz || framework_failure
echo
if [ ${fail} = 0 ] ; then
diff --git a/testsuite/fox6.lz b/testsuite/fox6.lz
new file mode 100644
index 0000000..8401b99
--- /dev/null
+++ b/testsuite/fox6.lz
Binary files differ
diff --git a/testsuite/fox6_mark.lz b/testsuite/fox6_mark.lz
new file mode 100644
index 0000000..32b2ac0
--- /dev/null
+++ b/testsuite/fox6_mark.lz
Binary files differ