summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2025-01-14 10:08:57 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2025-01-14 11:57:05 +0000
commit777cf7f2832314b284ecbfe70847d00031457dfc (patch)
tree5c6e49697839b0a1a872cc4dcfea831e054b1d57
parentReleasing debian version 1.4-2. (diff)
downloadlzd-777cf7f2832314b284ecbfe70847d00031457dfc.tar.xz
lzd-777cf7f2832314b284ecbfe70847d00031457dfc.zip
Merging upstream version 1.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--ChangeLog16
-rw-r--r--INSTALL5
-rw-r--r--Makefile.in12
-rw-r--r--NEWS9
-rw-r--r--README4
-rwxr-xr-xconfigure8
-rw-r--r--lzd.cc22
-rwxr-xr-xtestsuite/check.sh43
-rw-r--r--testsuite/em.lzbin0 -> 36 bytes
-rw-r--r--testsuite/fox_bm.lzbin80 -> 0 bytes
-rw-r--r--testsuite/fox_nz.lzbin0 -> 80 bytes
-rw-r--r--testsuite/test.txt6
-rw-r--r--testsuite/test.txt.lzbin7376 -> 7341 bytes
-rw-r--r--testsuite/test_em.txt.lzbin14024 -> 0 bytes
14 files changed, 77 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index f417214..bbed3c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-01-02 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 1.5 released.
+ * lzd.cc: Reject empty members and nonzero first LZMA byte.
+
2024-01-02 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.4 released.
@@ -6,7 +11,7 @@
2022-10-24 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.3 released.
- * lzd.cc (Range_decoder): Discard first byte explicitly.
+ * lzd.cc (Range_decoder): Discard first LZMA byte explicitly.
2021-01-04 Antonio Diaz Diaz <antonio@gnu.org>
@@ -28,7 +33,7 @@
* Version 1.0 released.
* lzd.cc: Minor code improvements.
- * check.sh: A POSIX shell is required to run the tests.
+ * check.sh: Require a POSIX shell.
2016-05-10 Antonio Diaz Diaz <antonio@gnu.org>
@@ -75,8 +80,7 @@
* Version 0.1 released.
-Copyright (C) 2013-2024 Antonio Diaz Diaz.
+Copyright (C) 2013-2025 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
-modify it.
+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 modify it.
diff --git a/INSTALL b/INSTALL
index 2c82368..97a4fa6 100644
--- a/INSTALL
+++ b/INSTALL
@@ -4,7 +4,8 @@ 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.
-Gcc is available at http://gcc.gnu.org.
+Gcc is available at http://gcc.gnu.org
+Lzip is available at http://www.nongnu.org/lzip/lzip.html
Procedure
@@ -52,7 +53,7 @@ After running 'configure', you can run 'make' and 'make install' as
explained above.
-Copyright (C) 2013-2024 Antonio Diaz Diaz.
+Copyright (C) 2013-2025 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 120a41b..47358f5 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -2,8 +2,8 @@
DISTNAME = $(pkgname)-$(pkgversion)
INSTALL = install
INSTALL_PROGRAM = $(INSTALL) -m 755
-INSTALL_DATA = $(INSTALL) -m 644
INSTALL_DIR = $(INSTALL) -d -m 755
+INSTALL_DATA = $(INSTALL) -m 644
SHELL = /bin/sh
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1
@@ -26,7 +26,8 @@ $(progname) : $(objs)
# prevent 'make' from trying to remake source files
$(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ;
-%.h %.cc : ;
+MAKEFLAGS += -r
+.SUFFIXES :
$(objs) : Makefile
@@ -40,8 +41,7 @@ $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
man : $(VPATH)/doc/$(progname).1
$(VPATH)/doc/$(progname).1 : $(progname)
- help2man -n 'educational decompressor for the lzip format' \
- -o $@ --no-info ./$(progname)
+ help2man -n 'educational decompressor for the lzip format' -o $@ --no-info ./$(progname)
Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
./config.status
@@ -108,10 +108,10 @@ dist : doc
$(DISTNAME)/*.cc \
$(DISTNAME)/testsuite/check.sh \
$(DISTNAME)/testsuite/test.txt \
+ $(DISTNAME)/testsuite/em.lz \
$(DISTNAME)/testsuite/fox.lz \
$(DISTNAME)/testsuite/fox_*.lz \
- $(DISTNAME)/testsuite/test.txt.lz \
- $(DISTNAME)/testsuite/test_em.txt.lz
+ $(DISTNAME)/testsuite/test.txt.lz
rm -f $(DISTNAME)
lzip -v -9 $(DISTNAME).tar
diff --git a/NEWS b/NEWS
index be2c30b..370140c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,7 @@
-Changes in version 1.4:
+Changes in version 1.5:
-Define constants 'header_size' and 'trailer_size' instead of using 6 and 20.
-(Lzd is supposed to be educational, and using numbers is bad practice).
+lzd now exits with error status 2 if any empty member is found in a
+multimember file.
+
+lzd now exits with error status 2 if the first byte of the LZMA stream is
+not 0.
diff --git a/README b/README
index 03fb742..1dff5ae 100644
--- a/README
+++ b/README
@@ -1,3 +1,5 @@
+See the file INSTALL for compilation and installation instructions.
+
Description
Lzd is a simplified decompressor for the lzip format with an educational
@@ -28,7 +30,7 @@ definition of Markov chains), G.N.N. Martin (for the definition of range
encoding), and Igor Pavlov (for putting all the above together in LZMA).
-Copyright (C) 2013-2024 Antonio Diaz Diaz.
+Copyright (C) 2013-2025 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute, and modify it.
diff --git a/configure b/configure
index a84fda2..0345a3f 100755
--- a/configure
+++ b/configure
@@ -1,12 +1,12 @@
#! /bin/sh
# configure script for Lzd - Educational decompressor for the lzip format
-# Copyright (C) 2013-2024 Antonio Diaz Diaz.
+# Copyright (C) 2013-2025 Antonio Diaz Diaz.
#
# This configure script is free software: you have unlimited permission
# to copy, distribute, and modify it.
pkgname=lzd
-pkgversion=1.4
+pkgversion=1.5
progname=lzd
srctrigger=lzd.cc
@@ -109,7 +109,7 @@ while [ $# != 0 ] ; do
exit 1 ;;
esac
- # Check if the option took a separate argument
+ # Check whether the option took a separate argument
if [ "${arg2}" = yes ] ; then
if [ $# != 0 ] ; then args="${args} \"$1\"" ; shift
else echo "configure: Missing argument to '${option}'" 1>&2
@@ -171,7 +171,7 @@ echo "MAKEINFO = ${MAKEINFO}"
rm -f Makefile
cat > Makefile << EOF
# Makefile for Lzd - Educational decompressor for the lzip format
-# Copyright (C) 2013-2024 Antonio Diaz Diaz.
+# Copyright (C) 2013-2025 Antonio Diaz Diaz.
# This file was generated automatically by configure. Don't edit.
#
# This Makefile is free software: you have unlimited permission
diff --git a/lzd.cc b/lzd.cc
index 3cf3f13..4d9e40b 100644
--- a/lzd.cc
+++ b/lzd.cc
@@ -1,5 +1,5 @@
/* Lzd - Educational decompressor for the lzip format
- Copyright (C) 2013-2024 Antonio Diaz Diaz.
+ Copyright (C) 2013-2025 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -149,7 +149,8 @@ public:
Range_decoder()
: member_pos( header_size ), code( 0 ), range( 0xFFFFFFFFU )
{
- get_byte(); // discard first byte of the LZMA stream
+ if( get_byte() != 0 ) // check first LZMA byte
+ { std::fputs( "Nonzero first LZMA byte.\n", stderr ); std::exit( 2 ); }
for( int i = 0; i < 4; ++i ) code = ( code << 8 ) | get_byte();
}
@@ -392,8 +393,7 @@ bool LZ_decoder::decode_member() // Return false if error
direct_bits );
else
{
- rep0 +=
- rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
+ rep0 += rdec.decode( direct_bits-dis_align_bits ) << dis_align_bits;
rep0 += rdec.decode_tree_reversed( bm_align, dis_align_bits );
if( rep0 == 0xFFFFFFFFU ) // marker found
{
@@ -423,7 +423,7 @@ int main( const int argc, const char * const argv[] )
"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) 2024 Antonio Diaz Diaz.\n"
+ "\nCopyright (C) 2025 Antonio Diaz Diaz.\n"
"License 2-clause BSD.\n"
"This is free software: you are free to change and redistribute "
"it.\nThere is NO WARRANTY, to the extent permitted by law.\n"
@@ -438,6 +438,7 @@ int main( const int argc, const char * const argv[] )
setmode( STDOUT_FILENO, O_BINARY );
#endif
+ bool empty = false, multi = false;
for( bool first_member = true; ; first_member = false )
{
Lzip_header header; // check header
@@ -457,7 +458,7 @@ int main( const int argc, const char * const argv[] )
LZ_decoder decoder( dict_size ); // decode LZMA stream
if( !decoder.decode_member() )
- { std::fputs( "Data error\n", stderr ); return 2; }
+ { std::fputs( "Data error.\n", stderr ); return 2; }
Lzip_trailer trailer; // check trailer
for( int i = 0; i < trailer_size; ++i ) trailer[i] = decoder.get_byte();
@@ -465,24 +466,27 @@ int main( const int argc, const char * const argv[] )
unsigned crc = 0;
for( int i = 3; i >= 0; --i ) crc = ( crc << 8 ) + trailer[i];
if( crc != decoder.crc() )
- { std::fputs( "CRC mismatch\n", stderr ); retval = 2; }
+ { std::fputs( "CRC mismatch.\n", stderr ); retval = 2; }
unsigned long long data_size = 0;
for( int i = 11; i >= 4; --i )
data_size = ( data_size << 8 ) + trailer[i];
if( data_size != decoder.data_position() )
- { std::fputs( "Data size mismatch\n", stderr ); retval = 2; }
+ { std::fputs( "Data size mismatch.\n", stderr ); retval = 2; }
+ multi = !first_member; if( data_size == 0 ) empty = true;
unsigned long long member_size = 0;
for( int i = 19; i >= 12; --i )
member_size = ( member_size << 8 ) + trailer[i];
if( member_size != decoder.member_position() )
- { std::fputs( "Member size mismatch\n", stderr ); retval = 2; }
+ { std::fputs( "Member size mismatch.\n", stderr ); retval = 2; }
if( retval ) return retval;
}
if( std::fclose( stdout ) != 0 )
{ std::fprintf( stderr, "Error closing stdout: %s\n",
std::strerror( errno ) ); return 1; }
+ if( empty && multi )
+ { std::fputs( "Empty member not allowed.\n", stderr ); return 2; }
return 0;
}
diff --git a/testsuite/check.sh b/testsuite/check.sh
index b041fe8..9fb3925 100755
--- a/testsuite/check.sh
+++ b/testsuite/check.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# check script for Lzd - Educational decompressor for the lzip format
-# Copyright (C) 2013-2024 Antonio Diaz Diaz.
+# Copyright (C) 2013-2025 Antonio Diaz Diaz.
#
# This script is free software: you have unlimited permission
# to copy, distribute, and modify it.
@@ -30,8 +30,9 @@ cd "${objdir}"/tmp || framework_failure
in="${testdir}"/test.txt
in_lz="${testdir}"/test.txt.lz
-in_em="${testdir}"/test_em.txt.lz
+em_lz="${testdir}"/em.lz
fox_lz="${testdir}"/fox.lz
+fnz_lz="${testdir}"/fox_nz.lz
fail=0
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
@@ -40,10 +41,8 @@ printf "testing lzd-%s..." "$2"
"${LZIP}" < "${in}" 2> /dev/null
[ $? = 2 ] || test_failed $LINENO
-for i in "${in_lz}" "${in_em}" ; do
- "${LZIP}" < "$i" > out || test_failed $LINENO "$i"
- cmp "${in}" out || test_failed $LINENO "$i"
-done
+"${LZIP}" < "${in_lz}" > out || test_failed $LINENO
+cmp "${in}" out || test_failed $LINENO
cat "${in}" "${in}" > in2 || framework_failure
cat "${in_lz}" "${in_lz}" | "${LZIP}" > out2 || test_failed $LINENO
@@ -56,9 +55,27 @@ printf "\ngarbage" >> out2.lz || framework_failure
cmp in2 out2 || test_failed $LINENO
rm -f in2 out2 out2.lz || framework_failure
+touch empty || framework_failure
+"${LZIP}" -d < "${em_lz}" > em || test_failed $LINENO
+cmp empty em || test_failed $LINENO
+
printf "\ntesting bad input..."
-for i in fox_bm.lz fox_v2.lz fox_s11.lz fox_de20.lz \
+cat "${em_lz}" "${em_lz}" | "${LZIP}" -d > em 2> /dev/null
+[ $? = 2 ] || test_failed $LINENO
+cmp empty em || test_failed $LINENO
+rm -f empty em || framework_failure
+cat "${em_lz}" "${in_lz}" | "${LZIP}" -d > out 2> /dev/null
+[ $? = 2 ] || test_failed $LINENO
+cmp "${in}" out || test_failed $LINENO
+cat "${in_lz}" "${em_lz}" | "${LZIP}" -d > out 2> /dev/null
+[ $? = 2 ] || test_failed $LINENO
+cmp "${in}" out || test_failed $LINENO
+
+"${LZIP}" < "${fnz_lz}" 2> /dev/null
+[ $? = 2 ] || test_failed $LINENO
+
+for i in fox_v2.lz fox_s11.lz fox_de20.lz \
fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do
"${LZIP}" < "${testdir}"/$i > /dev/null 2>&1
[ $? = 2 ] || test_failed $LINENO $i
@@ -70,24 +87,24 @@ for i in fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do
[ $? = 2 ] || test_failed $LINENO $i
cmp fox out || test_failed $LINENO $i
done
-rm -f fox out || framework_failure
+rm -f fox || framework_failure
cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure
cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure
-if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null &&
- [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then
+if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null &&
+ [ -e trunc.lz ] && cmp in2.lz trunc.lz ; then
# can't detect truncated header of non-first member
- for i in 6 20 14734 14758 ; do
+ for i in 6 20 14664 14688 ; do
dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
"${LZIP}" < trunc.lz > /dev/null 2>&1
[ $? = 2 ] || test_failed $LINENO $i
done
else
- printf "\nwarning: skipping truncation test: 'dd' does not work on your system."
+ printf "warning: skipping truncation test: 'dd' does not work on your system."
fi
rm -f in2.lz in3.lz trunc.lz || framework_failure
-cat "${in_lz}" > ingin.lz || framework_failure
+cp "${in_lz}" ingin.lz || framework_failure
printf "g" >> ingin.lz || framework_failure
cat "${in_lz}" >> ingin.lz || framework_failure
"${LZIP}" -d < ingin.lz > out || test_failed $LINENO
diff --git a/testsuite/em.lz b/testsuite/em.lz
new file mode 100644
index 0000000..ec60725
--- /dev/null
+++ b/testsuite/em.lz
Binary files differ
diff --git a/testsuite/fox_bm.lz b/testsuite/fox_bm.lz
deleted file mode 100644
index d71914f..0000000
--- a/testsuite/fox_bm.lz
+++ /dev/null
Binary files differ
diff --git a/testsuite/fox_nz.lz b/testsuite/fox_nz.lz
new file mode 100644
index 0000000..44a4b58
--- /dev/null
+++ b/testsuite/fox_nz.lz
Binary files differ
diff --git a/testsuite/test.txt b/testsuite/test.txt
index 9196a3a..423f0c0 100644
--- a/testsuite/test.txt
+++ b/testsuite/test.txt
@@ -1,8 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -339,8 +338,7 @@ Public License instead of this License.
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
diff --git a/testsuite/test.txt.lz b/testsuite/test.txt.lz
index 22cea6e..5dc169f 100644
--- a/testsuite/test.txt.lz
+++ b/testsuite/test.txt.lz
Binary files differ
diff --git a/testsuite/test_em.txt.lz b/testsuite/test_em.txt.lz
deleted file mode 100644
index 7e96250..0000000
--- a/testsuite/test_em.txt.lz
+++ /dev/null
Binary files differ