--- rzip-2.1.old/Makefile.in +++ rzip-2.1/Makefile.in @@ -4,7 +4,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ INSTALL_BIN=$(exec_prefix)/bin -INSTALL_MAN=$(prefix)/man +INSTALL_MAN=$(prefix)/share/man LIBS=@LIBS@ CC=@CC@ @@ -24,7 +24,7 @@ # note that the -I. is needed to handle config.h when using VPATH .c.o: - $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@ + $(CC) -I. -I$(srcdir) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ all: rzip @@ -33,11 +33,13 @@ install: all -mkdir -p ${INSTALL_BIN} ${INSTALLCMD} -m 755 rzip ${INSTALL_BIN} + ln ${INSTALL_BIN}/rzip ${INSTALL_BIN}/runzip -mkdir -p ${INSTALL_MAN}/man1 ${INSTALLCMD} -m 644 $(srcdir)/rzip.1 ${INSTALL_MAN}/man1/ + ln ${INSTALL_MAN}/man1/rzip.1 ${INSTALL_MAN}/man1/runzip.1 rzip: $(OBJS) - $(CC) $(CFLAGS) -o rzip $(OBJS) $(LIBS) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o rzip $(OBJS) $(LIBS) rzip.1: rzip.yo yodl2man -o rzip.1 rzip.yo --- rzip-2.1.old/configure.in +++ rzip-2.1/configure.in @@ -11,7 +11,7 @@ # Thanks to Martin Pool if test x"$GCC" = xyes then - CFLAGS="-g -Wall -O3" +# CFLAGS="-g -Wall -O3" AC_MSG_NOTICE([Setting gcc options: $CFLAGS]) fi --- rzip-2.1.old/main.c +++ rzip-2.1/main.c @@ -25,17 +25,18 @@ printf("Copright (C) Andrew Tridgell 1998-2003\n\n"); printf("usage: rzip [options] \n"); printf(" Options:\n"); - printf(" -0 fastest (worst) compression\n"); - printf(" -6 default compression level\n"); - printf(" -9 slowest (best) compression\n"); - printf(" -d decompress\n"); - printf(" -o filename specify the output file name\n"); - printf(" -S suffix specify compressed suffix (default '.rz')\n"); - printf(" -f force overwrite of any existing files\n"); - printf(" -k keep existing files\n"); - printf(" -P show compression progress\n"); - printf(" -L level set compression level\n"); - printf(" -V show version\n"); + printf(" -0, --worst fastest (worst) compression\n"); + printf(" -6 default compression level\n"); + printf(" -9, --best slowest (best) compression\n"); + printf(" -d, --decompress decompress\n"); + printf(" -f, --force force overwrite of any existing files\n"); + printf(" -o, --output FILENAME specify the output file name\n"); + printf(" -k, --keep keep existing files\n"); + printf(" -L, --level LEVEL set compression level\n"); + printf(" -P, --progress show compression progress\n"); + printf(" -S, --suffix SUFFIX specify compressed suffix (default '.rz')\n"); + printf(" -v, --verbose increase verbosity\n"); + printf(" -V, --version show version\n"); #if 0 /* damn, this will be quite hard to do */ printf(" -t test compressed file integrity\n"); @@ -128,6 +129,8 @@ { int fd_in, fd_out = -1, fd_hist = -1; off_t expected_size; + struct stat sb; + struct utimbuf utb; if (control->outname) { control->outfile = strdup(control->outname); @@ -143,6 +146,8 @@ control->outfile[strlen(control->infile) - strlen(control->suffix)] = 0; } + stat(control->infile,&sb); + fd_in = open(control->infile,O_RDONLY); if (fd_in == -1) { fatal("Failed to open %s: %s\n", @@ -190,6 +195,10 @@ } } + utb.actime=sb.st_atime; + utb.modtime=sb.st_mtime; + utime(control->outfile,&utb); + free(control->outfile); } @@ -199,6 +208,8 @@ static void compress_file(struct rzip_control *control) { int fd_in, fd_out; + struct stat sb; + struct utimbuf utb; if (strlen(control->suffix) <= strlen(control->infile) && strcmp(control->suffix, control->infile + strlen(control->infile) - strlen(control->suffix)) == 0) { @@ -218,6 +229,11 @@ strcat(control->outfile, control->suffix); } + stat(control->infile,&sb); + if (S_ISDIR(sb.st_mode)) { + fatal("Can't compress %s: %s\n", control->infile, strerror(EISDIR)); + } + fd_in = open(control->infile,O_RDONLY); if (fd_in == -1) { fatal("Failed to open %s: %s\n", control->infile, strerror(errno)); @@ -248,6 +264,10 @@ } } + utb.actime=sb.st_atime; + utb.modtime=sb.st_mtime; + utime(control->outfile,&utb); + free(control->outfile); } @@ -267,7 +287,25 @@ control.flags |= FLAG_DECOMPRESS; } - while ((c = getopt(argc, argv, "h0123456789dS:tVvkfPo:L:")) != -1) { + static struct option options[] = + { + { "level", required_argument, NULL, 'L' }, + { "decompress", no_argument, NULL, 'd' }, + { "suffix", required_argument, NULL, 'S' }, + { "output", required_argument, NULL, 'o' }, + { "force", no_argument, NULL, 'f' }, + { "keep", no_argument, NULL, 'k' }, + { "verbose", no_argument, NULL, 'v' }, + { "progress", no_argument, NULL, 'P' }, + { "version", no_argument, NULL, 'V' }, + { "best", no_argument, NULL, '9' }, + { "worst", no_argument, NULL, '0' }, + { "help", no_argument, NULL, 'h' } + }; + + while ((c = getopt_long(argc, argv, "h0123456789dS:tVvkfPo:L:", options, + NULL)) != -1) { + if (isdigit(c)) { control.compression_level = c - '0'; continue; --- rzip-2.1.old/runzip.c +++ rzip-2.1/runzip.c @@ -31,34 +31,34 @@ static inline unsigned read_u16(void *ss, int stream) { unsigned ret; - ret = read_u8(ss, stream); - ret |= read_u8(ss, stream)<<8; + ret = ((unsigned)read_u8(ss, stream)); + ret |= ((unsigned)read_u8(ss, stream))<<8; return ret; } static inline unsigned read_u32(void *ss, int stream) { unsigned ret; - ret = read_u8(ss, stream); - ret |= read_u8(ss, stream)<<8; - ret |= read_u8(ss, stream)<<16; - ret |= read_u8(ss, stream)<<24; + ret = ((unsigned)read_u8(ss, stream)); + ret |= ((unsigned)read_u8(ss, stream))<<8; + ret |= ((unsigned)read_u8(ss, stream))<<16; + ret |= ((unsigned)read_u8(ss, stream))<<24; return ret; } static inline unsigned read_u24(void *ss, int stream) { unsigned ret; - ret = read_u8(ss, stream); - ret |= read_u8(ss, stream)<<8; - ret |= read_u8(ss, stream)<<16; + ret = ((unsigned)read_u8(ss, stream)); + ret |= ((unsigned)read_u8(ss, stream))<<8; + ret |= ((unsigned)read_u8(ss, stream))<<16; return ret; } static int read_header(void *ss, uchar *head) { - *head = read_u8(ss, 0); + *head = ((unsigned)read_u8(ss, 0)); return read_u16(ss, 0); } @@ -72,7 +72,10 @@ fatal("Failed to allocate literal buffer of size %d\n", len); } - read_stream(ss, 1, buf, len); + int rd = read_stream(ss, 1, buf, len); + if (rd != len) { + fatal("Short read: %d < %d\n", rd, len); + } if (write(fd_out, buf, len) != len) { fatal("Failed to write literal buffer of size %d\n", len); } @@ -181,7 +184,11 @@ { off_t total = 0; while (total < expected_size) { - total += runzip_chunk(fd_in, fd_out, fd_hist); + off_t rd = runzip_chunk(fd_in, fd_out, fd_hist); + total += rd; + if (total < expected_size && rd == 0) { + fatal("Input file truncated!\n"); + } } return total; } --- rzip-2.1.old/rzip.1 +++ rzip-2.1/rzip.1 @@ -8,7 +8,7 @@ .SH "DESCRIPTION" .PP rzip is a file compression program designed to do particularly -well on very large files containing long distance redundency\&. +well on very large files containing long distance redundancy\&. .PP .SH "OPTIONS SUMMARY" .PP @@ -17,16 +17,16 @@ .nf - -0 fastest (worst) compression - -6 default compression - -9 slowest (best) compression - -d decompress - -o filename specify the output file name - -S suffix specify compressed suffix (default \&'\&.rz\&') - -f force overwrite of any existing files - -k keep existing files - -P show compression progress - -V show version + \-0 fastest (worst) compression + \-6 default compression + \-9 slowest (best) compression + \-d decompress + \-o filename specify the output file name + \-S suffix specify compressed suffix (default \&'\&.rz\&') + \-f force overwrite of any existing files + \-k keep existing files + \-P show compression progress + \-V show version .fi @@ -50,12 +50,12 @@ .IP "\fB-d\fP" Decompress\&. If this option is not used then rzip looks at the name used to launch the program\&. If it contains the string -\&'runzip\&' then the -d option is automatically set\&. +\&'runzip\&' then the \-d option is automatically set\&. .IP .IP "\fB-o\fP" Set the output file name\&. If this option is not set then the output file name is chosen based on the input name and the -suffix\&. The -o option cannot be used if more than one file name is +suffix\&. The \-o option cannot be used if more than one file name is specified on the command line\&. .IP .IP "\fB-S\fP" @@ -90,7 +90,7 @@ .PP The key difference between rzip and other well known compression algorithms is its ability to take advantage of very long distance -redundency\&. The well known deflate algorithm used in gzip uses a +redundancy\&. The well known deflate algorithm used in gzip uses a maximum history buffer of 32k\&. The block sorting algorithm used in bzip2 is limited to 900k of history\&. The history buffer in rzip can be up to 900MB long, several orders of magnitude larger than gzip or @@ -102,7 +102,7 @@ of quite similar files\&. It is also common to have a single file that contains large duplicated chunks over long distances, such as pdf files containing repeated copies of the same image\&. Most compression -programs won\&'t be able to take advantage of this redundency, and thus +programs won\&'t be able to take advantage of this redundancy, and thus might achieve a much lower compression ratio than rzip can achieve\&. .PP .SH "HISTORY" @@ -132,7 +132,7 @@ http://samba\&.org/~tridge/ .PP If you wish to report a problem or make a suggestion then please email -bugs-rzip@tridgell\&.net +bugs\-rzip@tridgell\&.net .PP rzip is released under the GNU General Public License version 2 or later\&. Please see the file COPYING for license details\&. --- rzip-2.1.old/rzip.h +++ rzip-2.1/rzip.h @@ -33,6 +33,8 @@ #include #include #include +#include +#include #ifdef HAVE_STRING_H #include @@ -44,6 +46,7 @@ #include #include +#include #ifdef HAVE_CTYPE_H #include --- rzip-2.1.old/rzip.yo +++ rzip-2.1/rzip.yo @@ -8,58 +8,62 @@ manpagedescription() rzip is a file compression program designed to do particularly -well on very large files containing long distance redundency. +well on very large files containing long distance redundancy. manpagesection(OPTIONS SUMMARY) Here is a summary of the options to rzip. verb( - -0 fastest (worst) compression - -6 default compression - -9 slowest (best) compression - -d decompress - -o filename specify the output file name - -S suffix specify compressed suffix (default '.rz') - -f force overwrite of any existing files - -k keep existing files - -P show compression progress - -V show version +-0, --worst fastest (worst) compression +-6 default compression level +-9, --best slowest (best) compression +-d, --decompress decompress +-f, --force force overwrite of any existing files +-o, --output FILENAME specify the output file name +-k, --keep keep existing files +-L, --level LEVEL set compression level +-P, --progress show compression progress +-S, --suffix SUFFIX specify compressed suffix (default '.rz') +-v, --verbose increase verbosity +-V, --version show version ) manpageoptions() startdit() -dit(bf(-h)) Print an options summary page +dit(bf(-h --help)) Print an options summary page -dit(bf(-V)) Print the rzip version number +dit(bf(-V --version)) Print the rzip version number -dit(bf(-0..9)) Set the compression level from 0 to 9. The default is -to use level 6, which is a reasonable compromise between speed and -compression. The compression level is also strongly related to how much -memory rzip uses, so if you are running rzip on a machine with limited -amounts of memory then you will probably want to choose a smaller level. - -dit(bf(-d)) Decompress. If this option is not used then rzip looks at -the name used to launch the program. If it contains the string -'runzip' then the -d option is automatically set. - -dit(bf(-o)) Set the output file name. If this option is not set then -the output file name is chosen based on the input name and the -suffix. The -o option cannot be used if more than one file name is +dit(bf(-0 (or --worst) to -9 (or --best) --level)) Set the compression level +from 0 to 9. The default is to use level 6, which is a reasonable compromise +between speed and compression. The compression level is also strongly related +to how much memory rzip uses, so if you are running rzip on a machine with +limited amounts of memory then you will probably want to choose a smaller +level. + +dit(bf(-d --decompress)) Decompress. If this option is not used then +rzip looks at the name used to launch the program. If it contains the +string 'runzip' then the -d option is automatically set. + +dit(bf(-o --output)) Set the output file name. If this option is not +set then the output file name is chosen based on the input name and +the suffix. The -o option cannot be used if more than one file name is specified on the command line. -dit(bf(-S)) Set the compression suffix. The default is '.rz'. +dit(bf(-S --suffix)) Set the compression suffix. The default is '.rz'. -dit(bf(-f)) If this option is not specified then rzip will not +dit(bf(-f --force)) If this option is not specified then rzip will not overwrite any existing files. If you set this option then rzip will silently overwrite any files as needed. -dit(bf(-k)) If this option is not specified then rzip will delete the -source file after successful compression or decompression. When this -option is specified then the source files are not deleted. +dit(bf(-k --keep)) If this option is not specified then rzip will +delete the source file after successful compression or +decompression. When this option is specified then the source files are +not deleted. -dit(bf(-P)) If this option is specified then rzip will show the -percentage progress while compressing. +dit(bf(-P --progress)) If this option is specified then rzip will show +the percentage progress while compressing. enddit() --- rzip-2.1.old/stream.c +++ rzip-2.1/stream.c @@ -147,16 +147,16 @@ return 0; } -static int read_buf(int f, uchar *p, int len) +static int read_buf(int f, uchar *p, unsigned int len) { int ret; ret = read(f, p, len); if (ret == -1) { - err_msg("Read of length %d failed - %s\n", len, strerror(errno)); + err_msg("Read of length %u failed - %s\n", len, strerror(errno)); return -1; } if (ret != len) { - err_msg("Partial read!? asked for %d bytes but got %d\n", len, ret); + err_msg("Partial read!? asked for %u bytes but got %d\n", len, ret); return -1; } return 0; @@ -399,7 +399,7 @@ if (sinfo->s[stream].buf) { free(sinfo->s[stream].buf); } - sinfo->s[stream].buf = malloc(u_len); + sinfo->s[stream].buf = malloc(c_len > u_len ? c_len : u_len); if (!sinfo->s[stream].buf) { return -1; }