[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

compress bug fixes and changes



Hi,

I changed the following things in compress:

o) when inflate() returns an error (for example if input data is corrupted) it
   falls into an endless loop calling inflate() over and over again.
   i changed this, so it doesn't loop anymore. should probably call
   inflateSync() here?
o) if SMALL is defined, there is one %s too much in the printf() used by
   the -V option.
o) added version string of nullopen.c to -V output
o) removed unnecessary initializations to 0 for variables cat and decomp
o) beutified -l output to make it line up with the headlines

Moritz

Index: gzopen.c
===================================================================
RCS file: /cvs/src/usr.bin/compress/gzopen.c,v
retrieving revision 1.14
diff -u -r1.14 gzopen.c
--- gzopen.c	17 Jul 2003 20:17:02 -0000	1.14
+++ gzopen.c	11 Nov 2003 12:11:39 -0000
@@ -407,6 +407,7 @@
 {
 	gz_stream *s = (gz_stream*)cookie;
 	u_char *start = buf; /* starting point for crc computation */
+	int infret;
 
 	s->z_stream.next_out = buf;
 	s->z_stream.avail_out = len;
@@ -422,7 +423,8 @@
 			s->z_stream.next_in = s->z_buf;
 		}
 
-		if (inflate(&(s->z_stream), Z_NO_FLUSH) == Z_STREAM_END) {
+		infret = inflate(&(s->z_stream), Z_NO_FLUSH);
+		if (infret == Z_STREAM_END) {
 			/* Check CRC and original size */
 			s->z_crc = crc32(s->z_crc, start,
 			    (uInt)(s->z_stream.next_out - start));
@@ -439,7 +441,8 @@
 			s->z_hlen += 2 * sizeof(int32_t);
 			s->z_eof = 1;
 			break;
-		}
+		} else if (infret != Z_OK)
+			break;
 	}
 	s->z_crc = crc32(s->z_crc, start,
 	    (uInt)(s->z_stream.next_out - start));
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/compress/main.c,v
retrieving revision 1.47
diff -u -r1.47 main.c
--- main.c	5 Sep 2003 21:03:36 -0000	1.47
+++ main.c	11 Nov 2003 12:11:40 -0000
@@ -148,7 +148,7 @@
 	char *nargv[512];	/* some estimate based on ARG_MAX */
 	int bits, exists, oreg, ch, error, i, rc, oflag;
 
-	bits = cat = oflag = decomp = 0;
+	bits = oflag = 0;
 	nosave = -1;
 	p = __progname;
 	if (p[0] == 'g') {
@@ -277,11 +277,10 @@
 			decomp++;
 			break;
 		case 'V':
-			printf("%s\n%s\n%s\n", main_rcsid,
+			printf("%s\n%s\n", main_rcsid, gz_rcsid);
 #ifndef SMALL
-			    z_rcsid,
+			printf("%s\n%s\n", z_rcsid, null_rcsid);
 #endif
-			    gz_rcsid);
 			exit (0);
 		case 'v':
 			verbose++;
@@ -786,25 +785,27 @@
 	static u_int nruns;
 	char *timestr;
 
-	if (name != NULL && strcmp(name, "/dev/stdout") == 0)
-		name += 5;
-
 	if (nruns == 0) {
 		if (verbose >= 0) {
 			if (verbose > 0)
-				fputs("method  crc     date  time  ", stdout);
-			puts("compressed  uncompr. ratio uncompressed_name");
+				fputs("method  crc      date   time  ", stdout);
+			puts("compressed  uncompressed  ratio  uncompressed_name");
 		}
 	}
 	nruns++;
 
 	if (name != NULL) {
+		if (strcmp(name, "/dev/stdout") == 0)
+			name += 5;
 		if (verbose > 0) {
 			timestr = ctime(&info->mtime) + 4;
 			timestr[12] = '\0';
-			printf("%.5s %08x %s ", method->name, info->crc, timestr);
+			if (timestr[4] == ' ')
+				timestr[4] = '0';
+			printf("%-7.7s %08x %s ", method->name, info->crc,
+				timestr);
 		}
-		printf("%9lld %9lld  %4.1f%% %s\n",
+		printf("%10lld    %10lld  %4.1f%%  %s\n",
 		    (long long)(info->total_in + info->hlen),
 		    (long long)info->total_out,
 		    (info->total_out - info->total_in) *
@@ -816,8 +817,8 @@
 		if (nruns < 3)		/* only do totals for > 1 files */
 			return;
 		if (verbose > 0)
-			fputs("                            ", stdout);
-		printf("%9lld %9lld  %4.1f%% (totals)\n",
+			fputs("                              ", stdout);
+		printf("%10lld    %10lld  %4.1f%%  (totals)\n",
 		    (long long)(compressed_total + header_total),
 		    (long long)uncompressed_total,
 		    (uncompressed_total - compressed_total) *



Visit your host, monkey.org