1
0
Fork 0

Merging upstream version 1.5.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-20 15:09:30 +01:00
parent ee850f05f4
commit bc1883f769
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
14 changed files with 77 additions and 48 deletions

View file

@ -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> 2024-01-02 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.4 released. * Version 1.4 released.
@ -6,7 +11,7 @@
2022-10-24 Antonio Diaz Diaz <antonio@gnu.org> 2022-10-24 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.3 released. * 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> 2021-01-04 Antonio Diaz Diaz <antonio@gnu.org>
@ -28,7 +33,7 @@
* Version 1.0 released. * Version 1.0 released.
* lzd.cc: Minor code improvements. * 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> 2016-05-10 Antonio Diaz Diaz <antonio@gnu.org>
@ -75,8 +80,7 @@
* Version 0.1 released. * 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, This file is a collection of facts, and thus it is not copyrightable, but just
but just in case, you have unlimited permission to copy, distribute, and in case, you have unlimited permission to copy, distribute, and modify it.
modify it.

View file

@ -4,7 +4,8 @@ You will need a C++98 compiler with support for 'long long'.
(gcc 3.3.6 or newer is recommended). (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 I use gcc 6.1.0 and 3.3.6, but the code should compile with any standards
compliant compiler. 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 Procedure
@ -52,7 +53,7 @@ After running 'configure', you can run 'make' and 'make install' as
explained above. 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, This file is free documentation: you have unlimited permission to copy,
distribute, and modify it. distribute, and modify it.

View file

@ -2,8 +2,8 @@
DISTNAME = $(pkgname)-$(pkgversion) DISTNAME = $(pkgname)-$(pkgversion)
INSTALL = install INSTALL = install
INSTALL_PROGRAM = $(INSTALL) -m 755 INSTALL_PROGRAM = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644
INSTALL_DIR = $(INSTALL) -d -m 755 INSTALL_DIR = $(INSTALL) -d -m 755
INSTALL_DATA = $(INSTALL) -m 644
SHELL = /bin/sh SHELL = /bin/sh
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1 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 # prevent 'make' from trying to remake source files
$(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ; $(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ;
%.h %.cc : ; MAKEFLAGS += -r
.SUFFIXES :
$(objs) : Makefile $(objs) : Makefile
@ -40,8 +41,7 @@ $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
man : $(VPATH)/doc/$(progname).1 man : $(VPATH)/doc/$(progname).1
$(VPATH)/doc/$(progname).1 : $(progname) $(VPATH)/doc/$(progname).1 : $(progname)
help2man -n 'educational decompressor for the lzip format' \ help2man -n 'educational decompressor for the lzip format' -o $@ --no-info ./$(progname)
-o $@ --no-info ./$(progname)
Makefile : $(VPATH)/configure $(VPATH)/Makefile.in Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
./config.status ./config.status
@ -108,10 +108,10 @@ dist : doc
$(DISTNAME)/*.cc \ $(DISTNAME)/*.cc \
$(DISTNAME)/testsuite/check.sh \ $(DISTNAME)/testsuite/check.sh \
$(DISTNAME)/testsuite/test.txt \ $(DISTNAME)/testsuite/test.txt \
$(DISTNAME)/testsuite/em.lz \
$(DISTNAME)/testsuite/fox.lz \ $(DISTNAME)/testsuite/fox.lz \
$(DISTNAME)/testsuite/fox_*.lz \ $(DISTNAME)/testsuite/fox_*.lz \
$(DISTNAME)/testsuite/test.txt.lz \ $(DISTNAME)/testsuite/test.txt.lz
$(DISTNAME)/testsuite/test_em.txt.lz
rm -f $(DISTNAME) rm -f $(DISTNAME)
lzip -v -9 $(DISTNAME).tar lzip -v -9 $(DISTNAME).tar

9
NEWS
View file

@ -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 now exits with error status 2 if any empty member is found in a
(Lzd is supposed to be educational, and using numbers is bad practice). multimember file.
lzd now exits with error status 2 if the first byte of the LZMA stream is
not 0.

4
README
View file

@ -1,3 +1,5 @@
See the file INSTALL for compilation and installation instructions.
Description Description
Lzd is a simplified decompressor for the lzip format with an educational 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). 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, This file is free documentation: you have unlimited permission to copy,
distribute, and modify it. distribute, and modify it.

8
configure vendored
View file

@ -1,12 +1,12 @@
#! /bin/sh #! /bin/sh
# configure script for Lzd - Educational decompressor for the lzip format # 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 # This configure script is free software: you have unlimited permission
# to copy, distribute, and modify it. # to copy, distribute, and modify it.
pkgname=lzd pkgname=lzd
pkgversion=1.4 pkgversion=1.5
progname=lzd progname=lzd
srctrigger=lzd.cc srctrigger=lzd.cc
@ -109,7 +109,7 @@ while [ $# != 0 ] ; do
exit 1 ;; exit 1 ;;
esac esac
# Check if the option took a separate argument # Check whether the option took a separate argument
if [ "${arg2}" = yes ] ; then if [ "${arg2}" = yes ] ; then
if [ $# != 0 ] ; then args="${args} \"$1\"" ; shift if [ $# != 0 ] ; then args="${args} \"$1\"" ; shift
else echo "configure: Missing argument to '${option}'" 1>&2 else echo "configure: Missing argument to '${option}'" 1>&2
@ -171,7 +171,7 @@ echo "MAKEINFO = ${MAKEINFO}"
rm -f Makefile rm -f Makefile
cat > Makefile << EOF cat > Makefile << EOF
# Makefile for Lzd - Educational decompressor for the lzip format # 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 file was generated automatically by configure. Don't edit.
# #
# This Makefile is free software: you have unlimited permission # This Makefile is free software: you have unlimited permission

22
lzd.cc
View file

@ -1,5 +1,5 @@
/* Lzd - Educational decompressor for the lzip format /* 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 This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided
@ -149,7 +149,8 @@ public:
Range_decoder() Range_decoder()
: member_pos( header_size ), code( 0 ), range( 0xFFFFFFFFU ) : 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(); 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 ); direct_bits );
else else
{ {
rep0 += rep0 += rdec.decode( direct_bits-dis_align_bits ) << dis_align_bits;
rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
rep0 += rdec.decode_tree_reversed( bm_align, dis_align_bits ); rep0 += rdec.decode_tree_reversed( bm_align, dis_align_bits );
if( rep0 == 0xFFFFFFFFU ) // marker found 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" "See the lzip manual for an explanation of the code.\n"
"\nUsage: %s [-d] < file.lz > file\n" "\nUsage: %s [-d] < file.lz > file\n"
"Lzd decompresses from standard input to standard output.\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" "License 2-clause BSD.\n"
"This is free software: you are free to change and redistribute " "This is free software: you are free to change and redistribute "
"it.\nThere is NO WARRANTY, to the extent permitted by law.\n" "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 ); setmode( STDOUT_FILENO, O_BINARY );
#endif #endif
bool empty = false, multi = false;
for( bool first_member = true; ; first_member = false ) for( bool first_member = true; ; first_member = false )
{ {
Lzip_header header; // check header 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 LZ_decoder decoder( dict_size ); // decode LZMA stream
if( !decoder.decode_member() ) 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 Lzip_trailer trailer; // check trailer
for( int i = 0; i < trailer_size; ++i ) trailer[i] = decoder.get_byte(); 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; unsigned crc = 0;
for( int i = 3; i >= 0; --i ) crc = ( crc << 8 ) + trailer[i]; for( int i = 3; i >= 0; --i ) crc = ( crc << 8 ) + trailer[i];
if( crc != decoder.crc() ) 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; unsigned long long data_size = 0;
for( int i = 11; i >= 4; --i ) for( int i = 11; i >= 4; --i )
data_size = ( data_size << 8 ) + trailer[i]; data_size = ( data_size << 8 ) + trailer[i];
if( data_size != decoder.data_position() ) 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; unsigned long long member_size = 0;
for( int i = 19; i >= 12; --i ) for( int i = 19; i >= 12; --i )
member_size = ( member_size << 8 ) + trailer[i]; member_size = ( member_size << 8 ) + trailer[i];
if( member_size != decoder.member_position() ) 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( retval ) return retval;
} }
if( std::fclose( stdout ) != 0 ) if( std::fclose( stdout ) != 0 )
{ std::fprintf( stderr, "Error closing stdout: %s\n", { std::fprintf( stderr, "Error closing stdout: %s\n",
std::strerror( errno ) ); return 1; } std::strerror( errno ) ); return 1; }
if( empty && multi )
{ std::fputs( "Empty member not allowed.\n", stderr ); return 2; }
return 0; return 0;
} }

View file

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# check script for Lzd - Educational decompressor for the lzip format # 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 # This script is free software: you have unlimited permission
# to copy, distribute, and modify it. # to copy, distribute, and modify it.
@ -30,8 +30,9 @@ cd "${objdir}"/tmp || framework_failure
in="${testdir}"/test.txt in="${testdir}"/test.txt
in_lz="${testdir}"/test.txt.lz in_lz="${testdir}"/test.txt.lz
in_em="${testdir}"/test_em.txt.lz em_lz="${testdir}"/em.lz
fox_lz="${testdir}"/fox.lz fox_lz="${testdir}"/fox.lz
fnz_lz="${testdir}"/fox_nz.lz
fail=0 fail=0
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; } test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
@ -40,10 +41,8 @@ printf "testing lzd-%s..." "$2"
"${LZIP}" < "${in}" 2> /dev/null "${LZIP}" < "${in}" 2> /dev/null
[ $? = 2 ] || test_failed $LINENO [ $? = 2 ] || test_failed $LINENO
for i in "${in_lz}" "${in_em}" ; do "${LZIP}" < "${in_lz}" > out || test_failed $LINENO
"${LZIP}" < "$i" > out || test_failed $LINENO "$i" cmp "${in}" out || test_failed $LINENO
cmp "${in}" out || test_failed $LINENO "$i"
done
cat "${in}" "${in}" > in2 || framework_failure cat "${in}" "${in}" > in2 || framework_failure
cat "${in_lz}" "${in_lz}" | "${LZIP}" > out2 || test_failed $LINENO 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 cmp in2 out2 || test_failed $LINENO
rm -f in2 out2 out2.lz || framework_failure 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..." 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 fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do
"${LZIP}" < "${testdir}"/$i > /dev/null 2>&1 "${LZIP}" < "${testdir}"/$i > /dev/null 2>&1
[ $? = 2 ] || test_failed $LINENO $i [ $? = 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 [ $? = 2 ] || test_failed $LINENO $i
cmp fox out || test_failed $LINENO $i cmp fox out || test_failed $LINENO $i
done 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}" > in2.lz || framework_failure
cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.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 && if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null &&
[ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then [ -e trunc.lz ] && cmp in2.lz trunc.lz ; then
# can't detect truncated header of non-first member # 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 dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
"${LZIP}" < trunc.lz > /dev/null 2>&1 "${LZIP}" < trunc.lz > /dev/null 2>&1
[ $? = 2 ] || test_failed $LINENO $i [ $? = 2 ] || test_failed $LINENO $i
done done
else 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 fi
rm -f in2.lz in3.lz trunc.lz || framework_failure 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 printf "g" >> ingin.lz || framework_failure
cat "${in_lz}" >> ingin.lz || framework_failure cat "${in_lz}" >> ingin.lz || framework_failure
"${LZIP}" -d < ingin.lz > out || test_failed $LINENO "${LZIP}" -d < ingin.lz > out || test_failed $LINENO

BIN
testsuite/em.lz Normal file

Binary file not shown.

Binary file not shown.

BIN
testsuite/fox_nz.lz Normal file

Binary file not shown.

View file

@ -1,8 +1,7 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 2, June 1991 Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
@ -339,8 +338,7 @@ Public License instead of this License.
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 2, June 1991 Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.

Binary file not shown.

Binary file not shown.