Permalink
Browse files

Exit with error if given a truncated .gz file.

(Previously zsyncmake would infinite loop.)
  • Loading branch information...
1 parent 1827f5c commit 1f4de48809727ed94d955986301ab4079c92673a Colin Phipps committed Jun 13, 2010
Showing with 9 additions and 2 deletions.
  1. +1 −0 c/NEWS
  2. +8 −2 c/make.c
View
@@ -1,6 +1,7 @@
Changes in 0.6.2
- fix for using zsync client on files >2GB on 32bit systems.
- improve some edge cases dealing with unusual seed data patterns.
+- fix infinite loop in zsyncmake when given a truncated (invalid) .gz
Changes in 0.6.1
- recompression support for gzip files made with zlib:gzio.c or gzip -n
View
@@ -1,4 +1,3 @@
-
/*
* zsync - client side rsync over http
* Copyright (C) 2004,2005,2009 Colin Phipps <cph@moria.org.uk>
@@ -243,11 +242,18 @@ void do_zstream(FILE * fin, FILE * fout, const char *bufsofar, size_t got) {
/* refill input buffer if empty */
if (zs.avail_in == 0) {
int rc = fread(inbuf, 1, inbufsz, fin);
- zs.next_in = inbuf;
if (rc < 0) {
perror("read");
exit(2);
}
+
+ /* Still expecting data (!eoz and avail_in == 0) but none there. */
+ if (rc == 0) {
+ fprintf(stderr, "Premature end of compressed data.\n");
+ exit(1);
+ }
+
+ zs.next_in = inbuf;
zs.avail_in = rc;
}
{

0 comments on commit 1f4de48

Please sign in to comment.