Module Name:    src
Committed By:   mrg
Date:           Fri Aug  4 07:27:08 UTC 2017

Modified Files:
        src/usr.bin/gzip: gzip.1 gzip.c unbzip2.c unpack.c unxz.c

Log Message:
add SIGINFO support.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/gzip/gzip.1
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/gzip/unbzip2.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/gzip/unpack.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.28 src/usr.bin/gzip/gzip.1:1.29
--- src/usr.bin/gzip/gzip.1:1.28	Sat Jun  3 21:28:48 2017
+++ src/usr.bin/gzip/gzip.1	Fri Aug  4 07:27:08 2017
@@ -1,6 +1,6 @@
-.\"	$NetBSD: gzip.1,v 1.28 2017/06/03 21:28:48 mrg Exp $
+.\"	$NetBSD: gzip.1,v 1.29 2017/08/04 07:27:08 mrg Exp $
 .\"
-.\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015 Matthew R. Green
+.\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015, 2017 Matthew R. Green
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -179,6 +179,13 @@ The
 utility exits 0 on success,
 1 on errors,
 and 2 if a warning occurs.
+.Sh SIGNALS
+.Nm
+responds to the following signals:
+.Bl -tag -width indent
+.It Dv SIGINFO
+Report progress to standard error.
+.El
 .Sh SEE ALSO
 .Xr bzip2 1 ,
 .Xr compress 1 ,
@@ -202,7 +209,7 @@ program for
 This manual documents
 .Nx
 .Nm
-version 20150113.
+version 20170803.
 .Sh AUTHORS
 This implementation of
 .Nm

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.110 src/usr.bin/gzip/gzip.c:1.111
--- src/usr.bin/gzip/gzip.c:1.110	Sat Jun  3 21:28:48 2017
+++ src/usr.bin/gzip/gzip.c	Fri Aug  4 07:27:08 2017
@@ -1,7 +1,7 @@
-/*	$NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $	*/
 
 /*
- * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015
+ * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
  *    Matthew R. Green
  * All rights reserved.
  *
@@ -30,8 +30,8 @@
 #include <sys/cdefs.h>
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
- 2009, 2010, 2011, 2015 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $");
+ 2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
+__RCSID("$NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $");
 #endif /* not lint */
 
 /*
@@ -161,7 +161,7 @@ static suffixes_t suffixes[] = {
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
 #define SUFFIX_MAXLEN	30
 
-static	const char	gzip_version[] = "NetBSD gzip 20150113";
+static	const char	gzip_version[] = "NetBSD gzip 20170803";
 
 static	int	cflag;			/* stdout mode */
 static	int	dflag;			/* decompress mode */
@@ -177,6 +177,7 @@ static	int	qflag;			/* quiet mode */
 static	int	rflag;			/* recursive mode */
 static	int	tflag;			/* test */
 static	int	vflag;			/* verbose mode */
+static	sig_atomic_t print_info = 0;
 #else
 #define		qflag	0
 #define		tflag	0
@@ -184,7 +185,7 @@ static	int	vflag;			/* verbose mode */
 
 static	int	exit_value = 0;		/* exit value */
 
-static	char	*infile;		/* name of file coming in */
+static	const char *infile;		/* name of file coming in */
 
 static	void	maybe_err(const char *fmt, ...) __printflike(1, 2) __dead;
 #if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) ||	\
@@ -213,8 +214,20 @@ static	const suffixes_t *check_suffix(ch
 static	ssize_t	read_retry(int, void *, size_t);
 
 #ifdef SMALL
+#define infile_set(f,t) infile_set(f)
+#endif
+static	void	infile_set(const char *newinfile, off_t total);
+
+#ifdef SMALL
 #define unlink_input(f, sb) unlink(f)
+#define check_siginfo() /* nothing */
+#define setup_signals() /* nothing */
+#define infile_newdata(t) /* nothing */
 #else
+static	off_t	infile_total;		/* total expected to read/write */
+static	off_t	infile_current;		/* current read/write */
+
+static	void	check_siginfo(void);
 static	off_t	cat_fd(unsigned char *, size_t, off_t *, int fd);
 static	void	prepend_gzip(char *, int *, char ***);
 static	void	handle_dir(char *);
@@ -222,6 +235,9 @@ static	void	print_verbage(const char *, 
 static	void	print_test(const char *, int);
 static	void	copymodes(int fd, const struct stat *, const char *file);
 static	int	check_outfile(const char *outfile);
+static	void	setup_signals(void);
+static	void	infile_newdata(size_t newdata);
+static	void	infile_clear(void);
 #endif
 
 #ifndef NO_BZIP2_SUPPORT
@@ -285,7 +301,7 @@ main(int argc, char **argv)
 #endif
 	int ch;
 
-	/* XXX set up signals */
+	setup_signals();
 
 #ifndef SMALL
 	if ((gzip = getenv("GZIP")) != NULL)
@@ -559,7 +575,7 @@ gz_compress(int in, int out, off_t *gsiz
 		origname = "";
 	}
 
-	i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c%c%c%s", 
+	i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c%c%c%s",
 		     GZIP_MAGIC0, GZIP_MAGIC1, Z_DEFLATED,
 		     *origname ? ORIG_NAME : 0,
 		     mtime & 0xff,
@@ -568,7 +584,7 @@ gz_compress(int in, int out, off_t *gsiz
 		     (mtime >> 24) & 0xff,
 		     numflag == 1 ? 4 : numflag == 9 ? 2 : 0,
 		     OS_CODE, origname);
-	if (i >= BUFLEN)     
+	if (i >= BUFLEN)
 		/* this need PATH_MAX > BUFLEN ... */
 		maybe_err("snprintf");
 	if (*origname)
@@ -609,6 +625,7 @@ gz_compress(int in, int out, off_t *gsiz
 			}
 			if (in_size == 0)
 				break;
+			infile_newdata(in_size);
 
 			crc = crc32(crc, (const Bytef *)inbufp, (unsigned)in_size);
 			in_tot += in_size;
@@ -658,7 +675,7 @@ gz_compress(int in, int out, off_t *gsiz
 		goto out;
 	}
 
-	i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c", 
+	i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c",
 		 (int)crc & 0xff,
 		 (int)(crc >> 8) & 0xff,
 		 (int)(crc >> 16) & 0xff,
@@ -750,6 +767,7 @@ gz_uncompress(int in, int out, char *pre
 	out_tot = 0;
 
 	for (;;) {
+		check_siginfo();
 		if ((z.avail_in == 0 || needmore) && done_reading == 0) {
 			ssize_t in_size;
 
@@ -766,6 +784,7 @@ gz_uncompress(int in, int out, char *pre
 			} else if (in_size == 0) {
 				done_reading = 1;
 			}
+			infile_newdata(in_size);
 
 			z.avail_in += in_size;
 			needmore = 0;
@@ -1059,7 +1078,7 @@ copymodes(int fd, const struct stat *sbp
 
 		(void)fchmod(fd, DEFFILEMODE & ~mask);
 		(void)umask(mask);
-		return; 
+		return;
 	}
 	sb = *sbp;
 
@@ -1164,7 +1183,49 @@ unlink_input(const char *file, const str
 		return;
 	unlink(file);
 }
+
+static void
+got_siginfo(int signo)
+{
+
+	print_info = 1;
+}
+
+static void
+setup_signals(void)
+{
+
+	signal(SIGINFO, got_siginfo);
+}
+
+static	void
+infile_newdata(size_t newdata)
+{
+
+	infile_current += newdata;
+}
+#endif
+
+static	void
+infile_set(const char *newinfile, off_t total)
+{
+
+	if (newinfile)
+		infile = newinfile;
+#ifndef SMALL
+	infile_total = total;
+#endif
+}
+
+static	void
+infile_clear(void)
+{
+
+	infile = NULL;
+#ifndef SMALL
+	infile_total = infile_current = 0;
 #endif
+}
 
 static const suffixes_t *
 check_suffix(char *file, int xlate)
@@ -1196,7 +1257,7 @@ file_compress(char *file, char *outfile,
 {
 	int in;
 	int out;
-	off_t size, insize;
+	off_t size, in_size;
 #ifndef SMALL
 	struct stat isb, osb;
 	const suffixes_t *suff;
@@ -1208,16 +1269,23 @@ file_compress(char *file, char *outfile,
 		return -1;
 	}
 
+#ifndef SMALL
+	if (fstat(in, &isb) != 0) {
+		close(in);
+		maybe_warn("can't stat %s", file);
+		return -1;
+	}
+	infile_set(file, isb.st_size);
+#endif
+
 	if (cflag == 0) {
 #ifndef SMALL
-		if (fstat(in, &isb) == 0) {
-			if (isb.st_nlink > 1 && fflag == 0) {
-				maybe_warnx("%s has %d other link%s -- "
-					    "skipping", file, isb.st_nlink - 1,
-					    isb.st_nlink == 1 ? "" : "s");
-				close(in);
-				return -1;
-			}
+		if (isb.st_nlink > 1 && fflag == 0) {
+			maybe_warnx("%s has %d other link%s -- "
+				    "skipping", file, isb.st_nlink - 1,
+				    isb.st_nlink == 1 ? "" : "s");
+			close(in);
+			return -1;
 		}
 
 		if (fflag == 0 && (suff = check_suffix(file, 0))
@@ -1253,19 +1321,19 @@ file_compress(char *file, char *outfile,
 	} else
 		out = STDOUT_FILENO;
 
-	insize = gz_compress(in, out, &size, basename(file), (uint32_t)isb.st_mtime);
+	in_size = gz_compress(in, out, &size, basename(file), (uint32_t)isb.st_mtime);
 
 	(void)close(in);
 
 	/*
-	 * If there was an error, insize will be -1.
+	 * If there was an error, in_size will be -1.
 	 * If we compressed to stdout, just return the size.
 	 * Otherwise stat the file and check it is the correct size.
 	 * We only blow away the file if we can stat the output and it
 	 * has the expected size.
 	 */
 	if (cflag != 0)
-		return insize == -1 ? -1 : size;
+		return in_size == -1 ? -1 : size;
 
 #ifndef SMALL
 	if (fstat(out, &osb) != 0) {
@@ -1310,6 +1378,7 @@ file_uncompress(char *file, char *outfil
 	unsigned char header1[4];
 	enum filetype method;
 	int fd, ofd, zfd = -1;
+	size_t in_size;
 #ifndef SMALL
 	ssize_t rv;
 	time_t timestamp = 0;
@@ -1323,6 +1392,16 @@ file_uncompress(char *file, char *outfil
 		maybe_warn("can't open %s", file);
 		goto lose;
 	}
+	if (fstat(fd, &isb) != 0) {
+		close(fd);
+		maybe_warn("can't stat %s", file);
+		goto lose;
+	}
+	if (S_ISREG(isb.st_mode))
+		in_size = isb.st_size;
+	else
+		in_size = 0;
+	infile_set(file, in_size);
 
 	strlcpy(outfile, file, outsize);
 	if (check_suffix(outfile, 1) == NULL && !(cflag || lflag)) {
@@ -1343,6 +1422,7 @@ file_uncompress(char *file, char *outfil
 			goto unexpected_EOF;
 		goto lose;
 	}
+	infile_newdata(rbytes);
 
 	method = file_gettype(header1);
 #ifndef SMALL
@@ -1365,6 +1445,7 @@ file_uncompress(char *file, char *outfil
 				maybe_warn("can't read %s", file);
 			goto lose;
 		}
+		infile_newdata(rv);
 		timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
 
 		if (header1[3] & ORIG_NAME) {
@@ -1393,7 +1474,7 @@ file_uncompress(char *file, char *outfil
 				else
 					dp++;
 				snprintf(outfile, outsize, "%.*s%.*s",
-						(int) (dp - file), 
+						(int) (dp - file),
 						file, (int) rbytes, nf);
 			}
 		}
@@ -1402,8 +1483,6 @@ file_uncompress(char *file, char *outfil
 	lseek(fd, 0, SEEK_SET);
 
 	if (cflag == 0 || lflag) {
-		if (fstat(fd, &isb) != 0)
-			goto lose;
 #ifndef SMALL
 		if (isb.st_nlink > 1 && lflag == 0 && fflag == 0) {
 			maybe_warnx("%s has %d other links -- skipping",
@@ -1417,7 +1496,11 @@ file_uncompress(char *file, char *outfil
 #endif
 	}
 
-	if (cflag == 0 && lflag == 0) {
+	if (cflag)
+		zfd = STDOUT_FILENO;
+	else if (lflag)
+		zfd = -1;
+	else {
 		zfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0600);
 		if (zfd == STDOUT_FILENO) {
 			/* We won't close STDOUT_FILENO later... */
@@ -1428,8 +1511,7 @@ file_uncompress(char *file, char *outfil
 			maybe_warn("can't open %s", outfile);
 			goto lose;
 		}
-	} else
-		zfd = STDOUT_FILENO;
+	}
 
 	switch (method) {
 #ifndef NO_BZIP2_SUPPORT
@@ -1515,7 +1597,7 @@ file_uncompress(char *file, char *outfil
 #endif
 	default:
 		if (lflag) {
-			print_list(fd, isb.st_size, outfile, isb.st_mtime);
+			print_list(fd, in_size, outfile, isb.st_mtime);
 			close(fd);
 			return -1;	/* XXX */
 		}
@@ -1590,6 +1672,25 @@ file_uncompress(char *file, char *outfil
 }
 
 #ifndef SMALL
+static void
+check_siginfo(void)
+{
+	if (print_info == 0)
+		return;
+	if (infile) {
+		if (infile_total) {
+			int pcent = (int)((100.0 * infile_current) / infile_total);
+
+			fprintf(stderr, "%s: done %llu/%llu bytes %d%%\n",
+				infile, (unsigned long long)infile_current,
+				(unsigned long long)infile_total, pcent);
+		} else
+			fprintf(stderr, "%s: done %llu bytes\n",
+				infile, (unsigned long long)infile_current);
+	}
+	print_info = 0;
+}
+
 static off_t
 cat_fd(unsigned char * prepend, size_t count, off_t *gsizep, int fd)
 {
@@ -1613,6 +1714,7 @@ cat_fd(unsigned char * prepend, size_t c
 			maybe_warn("read from fd %d", fd);
 			break;
 		}
+		infile_newdata(rv);
 
 		if (write(STDOUT_FILENO, buf, rv) != rv) {
 			maybe_warn("write to stdout");
@@ -1630,7 +1732,9 @@ cat_fd(unsigned char * prepend, size_t c
 static void
 handle_stdin(void)
 {
+	struct stat isb;
 	unsigned char header1[4];
+	size_t in_size;
 	off_t usize, gsize;
 	enum filetype method;
 	ssize_t bytes_read;
@@ -1641,29 +1745,32 @@ handle_stdin(void)
 #ifndef SMALL
 	if (fflag == 0 && lflag == 0 && isatty(STDIN_FILENO)) {
 		maybe_warnx("standard input is a terminal -- ignoring");
-		return;
+		goto out;
 	}
 #endif
 
-	if (lflag) {
-		struct stat isb;
+	if (fstat(STDIN_FILENO, &isb) < 0) {
+		maybe_warn("fstat");
+		goto out;
+	}
+	if (S_ISREG(isb.st_mode))
+		in_size = isb.st_size;
+	else
+		in_size = 0;
+	infile_set("(stdin)", in_size);
 
-		/* XXX could read the whole file, etc. */
-		if (fstat(STDIN_FILENO, &isb) < 0) {
-			maybe_warn("fstat");
-			return;
-		}
-		print_list(STDIN_FILENO, isb.st_size, "stdout", isb.st_mtime);
-		return;
+	if (lflag) {
+		print_list(STDIN_FILENO, in_size, infile, isb.st_mtime);
+		goto out;
 	}
 
 	bytes_read = read_retry(STDIN_FILENO, header1, sizeof header1);
 	if (bytes_read == -1) {
 		maybe_warn("can't read stdin");
-		return;
+		goto out;
 	} else if (bytes_read != sizeof(header1)) {
 		maybe_warnx("(stdin): unexpected end of file");
-		return;
+		goto out;
 	}
 
 	method = file_gettype(header1);
@@ -1672,13 +1779,13 @@ handle_stdin(void)
 #ifndef SMALL
 		if (fflag == 0) {
 			maybe_warnx("unknown compression format");
-			return;
+			goto out;
 		}
 		usize = cat_fd(header1, sizeof header1, &gsize, STDIN_FILENO);
 		break;
 #endif
 	case FT_GZIP:
-		usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO, 
+		usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO,
 			      (char *)header1, sizeof header1, &gsize, "(stdin)");
 		break;
 #ifndef NO_BZIP2_SUPPORT
@@ -1691,7 +1798,7 @@ handle_stdin(void)
 	case FT_Z:
 		if ((in = zdopen(STDIN_FILENO)) == NULL) {
 			maybe_warnx("zopen of stdin");
-			return;
+			goto out;
 		}
 
 		usize = zuncompress(in, stdout, (char *)header1,
@@ -1718,53 +1825,58 @@ handle_stdin(void)
 		print_verbage(NULL, NULL, usize, gsize);
 	if (vflag && tflag)
 		print_test("(stdin)", usize != -1);
-#endif 
+#else
+	(void)&usize;
+#endif
 
+out:
+	infile_clear();
 }
 
 static void
 handle_stdout(void)
 {
-	off_t gsize, usize;
+	off_t gsize;
+#ifndef SMALL
+	off_t usize;
 	struct stat sb;
 	time_t systime;
 	uint32_t mtime;
 	int ret;
 
-#ifndef SMALL
+	infile_set("(stdout)", 0);
+
 	if (fflag == 0 && isatty(STDOUT_FILENO)) {
 		maybe_warnx("standard output is a terminal -- ignoring");
 		return;
 	}
-#endif
+
 	/* If stdin is a file use its mtime, otherwise use current time */
 	ret = fstat(STDIN_FILENO, &sb);
-
-#ifndef SMALL
 	if (ret < 0) {
 		maybe_warn("Can't stat stdin");
 		return;
 	}
-#endif
 
-	if (S_ISREG(sb.st_mode))
+	if (S_ISREG(sb.st_mode)) {
+		infile_set("(stdout)", sb.st_size);
 		mtime = (uint32_t)sb.st_mtime;
-	else {
+	} else {
 		systime = time(NULL);
-#ifndef SMALL
 		if (systime == -1) {
 			maybe_warn("time");
 			return;
-		} 
-#endif
+		}
 		mtime = (uint32_t)systime;
 	}
 	 		
-	usize = gz_compress(STDIN_FILENO, STDOUT_FILENO, &gsize, "", mtime);
+	usize =
+#endif
+		gz_compress(STDIN_FILENO, STDOUT_FILENO, &gsize, "", mtime);
 #ifndef SMALL
         if (vflag && !tflag && usize != -1 && gsize != -1)
 		print_verbage(NULL, NULL, usize, gsize);
-#endif 
+#endif
 }
 
 /* do what is asked for, for the path name */
@@ -1830,7 +1942,7 @@ handle_file(char *file, struct stat *sbp
 	off_t usize, gsize;
 	char	outfile[PATH_MAX];
 
-	infile = file;
+	infile_set(file, sbp->st_size);
 	if (dflag) {
 		usize = file_uncompress(file, outfile, sizeof(outfile));
 #ifndef SMALL
@@ -1846,7 +1958,7 @@ handle_file(char *file, struct stat *sbp
 			return;
 		usize = sbp->st_size;
 	}
-
+	infile_clear();
 
 #ifndef SMALL
 	if (vflag && !tflag)
@@ -1900,7 +2012,9 @@ print_ratio(off_t in, off_t out, FILE *w
 	int len;
 
 	diff = in - out/2;
-	if (diff <= 0)
+	if (in == 0 && out == 0)
+		percent10 = 0;
+	else if (diff < 0)
 		/*
 		 * Output is more than double size of input! print -99.9%
 		 * Quite possibly we've failed to get the original size.

Index: src/usr.bin/gzip/unbzip2.c
diff -u src/usr.bin/gzip/unbzip2.c:1.13 src/usr.bin/gzip/unbzip2.c:1.14
--- src/usr.bin/gzip/unbzip2.c:1.13	Sat Dec  5 03:23:37 2009
+++ src/usr.bin/gzip/unbzip2.c	Fri Aug  4 07:27:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: unbzip2.c,v 1.13 2009/12/05 03:23:37 mrg Exp $	*/
+/*	$NetBSD: unbzip2.c,v 1.14 2017/08/04 07:27:08 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -63,6 +63,7 @@ unbzip2(int in, int out, char *pre, size
 		*bytes_in = prelen;
 
 	while (ret == BZ_OK) {
+		check_siginfo();
 	        if (bzs.avail_in == 0 && !end_of_file) {
 			ssize_t	n;
 
@@ -71,6 +72,7 @@ unbzip2(int in, int out, char *pre, size
 	                        maybe_err("read");
 	                if (n == 0)
 	                        end_of_file = 1;
+			infile_newdata(n);
 	                bzs.next_in = inbuf;
 	                bzs.avail_in = n;
 			if (bytes_in)

Index: src/usr.bin/gzip/unpack.c
diff -u src/usr.bin/gzip/unpack.c:1.2 src/usr.bin/gzip/unpack.c:1.3
--- src/usr.bin/gzip/unpack.c:1.2	Sat Nov  6 21:42:32 2010
+++ src/usr.bin/gzip/unpack.c	Fri Aug  4 07:27:08 2017
@@ -1,5 +1,5 @@
 /*	$FreeBSD: head/usr.bin/gzip/unpack.c 194579 2009-06-21 09:39:43Z delphij $	*/
-/*	$NetBSD: unpack.c,v 1.2 2010/11/06 21:42:32 mrg Exp $	*/
+/*	$NetBSD: unpack.c,v 1.3 2017/08/04 07:27:08 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2009 Xin LI <[email protected]>
@@ -153,6 +153,9 @@ unpack_parse_header(int in, int out, cha
 	ssize_t bytesread;		/* Bytes read from the file */
 	int i, j, thisbyte;
 
+	if (prelen > sizeof hdr)
+		maybe_err("prelen too long");
+
 	/* Prepend the header buffer if we already read some data */
 	if (prelen != 0)
 		memcpy(hdr, pre, prelen);
@@ -161,6 +164,7 @@ unpack_parse_header(int in, int out, cha
 	bytesread = read(in, hdr + prelen, PACK_HEADER_LENGTH - prelen);
 	if (bytesread < 0)
 		maybe_err("Error reading pack header");
+	infile_newdata(bytesread);
 
 	accepted_bytes(bytes_in, PACK_HEADER_LENGTH);
 
@@ -207,6 +211,7 @@ unpack_parse_header(int in, int out, cha
 	accepted_bytes(bytes_in, unpackd->treelevels);
 	if (unpackd->symbol_size > 256)
 		maybe_errx("Bad symbol table");
+	infile_newdata(unpackd->treelevels);
 
 	/* Allocate for the symbol table, point symbol_eob at the beginning */
 	unpackd->symbol_eob = unpackd->symbol = calloc(1, unpackd->symbol_size);
@@ -230,6 +235,7 @@ unpack_parse_header(int in, int out, cha
 				maybe_errx("Symbol table truncated");
 			*unpackd->symbol_eob++ = (char)thisbyte;
 		}
+		infile_newdata(unpackd->symbolsin[i]);
 		accepted_bytes(bytes_in, unpackd->symbolsin[i]);
 	}
 
@@ -267,6 +273,8 @@ unpack_decode(const unpack_descriptor_t 
 
 	while ((thisbyte = fgetc(unpackd->fpIn)) != EOF) {
 		accepted_bytes(bytes_in, 1);
+		infile_newdata(1);
+		check_siginfo();
 
 		/*
 		 * Split one bit from thisbyte, from highest to lowest,

Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.6 src/usr.bin/gzip/unxz.c:1.7
--- src/usr.bin/gzip/unxz.c:1.6	Fri Jan 29 15:19:01 2016
+++ src/usr.bin/gzip/unxz.c	Fri Aug  4 07:27:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: unxz.c,v 1.6 2016/01/29 15:19:01 christos Exp $	*/
+/*	$NetBSD: unxz.c,v 1.7 2017/08/04 07:27:08 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: unxz.c,v 1.6 2016/01/29 15:19:01 christos Exp $");
+__RCSID("$NetBSD: unxz.c,v 1.7 2017/08/04 07:27:08 mrg Exp $");
 
 #include <stdarg.h>
 #include <errno.h>
@@ -56,6 +56,7 @@ unxz(int i, int o, char *pre, size_t pre
 	strm.avail_in = read(i, ibuf + prelen, sizeof(ibuf) - prelen);
 	if (strm.avail_in == (size_t)-1)
 		maybe_err("read failed");
+	infile_newdata(strm.avail_in);
 	strm.avail_in += prelen;
 	*bytes_in = strm.avail_in;
 
@@ -72,6 +73,7 @@ unxz(int i, int o, char *pre, size_t pre
 	strm.avail_out = sizeof(obuf);
 
 	for (;;) {
+		check_siginfo();
 		if (strm.avail_in == 0) {
 			strm.next_in = ibuf;
 			strm.avail_in = read(i, ibuf, sizeof(ibuf));
@@ -83,6 +85,7 @@ unxz(int i, int o, char *pre, size_t pre
 				action = LZMA_FINISH;
 				break;
 			default:
+				infile_newdata(strm.avail_in);
 				*bytes_in += strm.avail_in;
 				break;
 			}

Reply via email to