bug? -z option and large compressed data

Yasuoka Masahiko yasuoka at yasuoka.net
Thu Jul 3 18:25:28 EST 2003


Hello developers,

I'm Yasuoka Masahiko from Japan.  I sent 2 messages about a bug on
token.c.  It appears like bellow,

   dev1: {79} % rsync -Iz install-disk2.iso 127.0.0.1:/var/tmp/install-disk2.iso
   deflate on token returned 0 (16384 bytes left)
   rsync error: error in rsync protocol data stream (code 12) at token.c(288)
   dev1: {80} % 

I think this is serious.  I hope you will fix this problem.

Previous patch I sent last week is still buggy,

On Sun, 29 Jun 2003 10:32:33 +0900 (JST)
Yasuoka Masahiko <yasuoka at yasuoka.net> wrote:
> > Let's looked at token.c.
> > 
> >     280      tx_strm.next_in = (Bytef *) map_ptr(buf, offset, toklen);
> >     281      tx_strm.avail_in = toklen;
> >     282      tx_strm.next_out = (Bytef *) obuf;
> >     283      tx_strm.avail_out = MAX_DATA_COUNT;
> >     284      r = deflate(&tx_strm, Z_INSERT_ONLY);
> >     285      if (r != Z_OK || tx_strm.avail_in != 0) {
> >     286              rprintf(FERROR, "deflate on token returned %d (%d bytes left)\n",
> >     287                      r, tx_strm.avail_in);
> >     288              exit_cleanup(RERR_STREAMIO);
> >     289      }
> > 
> > MAX_DATA_COUNT is 16383 and toklen may be 16384.  So, when deflate()'s
> > outputs data length is bigger than input, then above code will fail.
> > Normally output data length is smaller than input, but it is not true
> > to already compressed data.

In addition to, tx_strm context keeps pending output.  It must be
flushed here.

Please check bellow patch.
***
Index: token.c
===================================================================
RCS file: /vol/cvs/datacube/src/auxcmd/rsync/token.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 token.c
--- token.c	8 Apr 2002 08:35:30 -0000	1.1.1.1
+++ token.c	3 Jul 2003 07:50:44 -0000
@@ -279,14 +279,25 @@ send_deflated_token(int f, int token,
 		   history and hash table */
 		tx_strm.next_in = (Bytef *) map_ptr(buf, offset, toklen);
 		tx_strm.avail_in = toklen;
-		tx_strm.next_out = (Bytef *) obuf;
-		tx_strm.avail_out = MAX_DATA_COUNT;
-		r = deflate(&tx_strm, Z_INSERT_ONLY);
-		if (r != Z_OK || tx_strm.avail_in != 0) {
+		do {
+			tx_strm.next_out = (Bytef *) obuf;
+			tx_strm.avail_out = MAX_DATA_COUNT;
+			r = deflate(&tx_strm, Z_INSERT_ONLY);
+			if (r != Z_OK) {
+				rprintf(FERROR, "deflate on token returned %d "
+				    "(%d bytes left)\n", r, tx_strm.avail_in);
+				exit_cleanup(RERR_STREAMIO);
+			}
+		} while (tx_strm.avail_out == 0 && tx_strm.avail_in > 0);
+		if (tx_strm.avail_in != 0) {
 			rprintf(FERROR, "deflate on token returned %d (%d bytes left)\n",
 				r, tx_strm.avail_in);
 			exit_cleanup(RERR_STREAMIO);
 		}
+		/* flush out pending output */
+		tx_strm.next_out = (Bytef *) obuf;
+		tx_strm.avail_out = MAX_DATA_COUNT;
+		r = deflate(&tx_strm, Z_SYNC_FLUSH);
 	}
 }
 
***
 
--yasuoka

    Yasuoka Masahiko (yasuoka at yasuoka.net)
    Second Software Inc.   http://www.second-software.com/



More information about the rsync mailing list