svn commit: r201498 - stable/6/sys/opencrypto

Bjoern A. Zeeb bz at FreeBSD.org
Mon Jan 4 14:41:32 UTC 2010


Author: bz
Date: Mon Jan  4 14:41:31 2010
New Revision: 201498
URL: http://svn.freebsd.org/changeset/base/201498

Log:
  MFC r199887:
  
    Z_PARTIAL_FLUSH is marked deprecated. Z_SYNC_FLUSH is the suggested
    replacement but only use it for inflate. For deflate use Z_FINISH
    as Z_SYNC_FLUSH adds a trailing marker in some cases that inflate(),
    despite the comment in zlib, does not seem to cope well with, resulting
    in errors when uncompressing exactly fills the output buffer without
    a Z_STREAM_END and a successive call returns an error.

Modified:
  stable/6/sys/opencrypto/deflate.c
Directory Properties:
  stable/6/sys/   (props changed)
  stable/6/sys/contrib/pf/   (props changed)
  stable/6/sys/dev/cxgb/   (props changed)

Modified: stable/6/sys/opencrypto/deflate.c
==============================================================================
--- stable/6/sys/opencrypto/deflate.c	Mon Jan  4 14:35:36 2010	(r201497)
+++ stable/6/sys/opencrypto/deflate.c	Mon Jan  4 14:41:31 2010	(r201498)
@@ -113,13 +113,17 @@ deflate_global(data, size, decomp, out)
 	if (error != Z_OK)
 		goto bad;
 	for (;;) {
-		error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) :
-				 deflate(&zbuf, Z_PARTIAL_FLUSH);
+		error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) :
+				 deflate(&zbuf, Z_FINISH);
 		if (error != Z_OK && error != Z_STREAM_END)
 			goto bad;
-		else if (zbuf.avail_in == 0 && zbuf.avail_out != 0)
-			goto end;
-		else if (zbuf.avail_out == 0 && i < (ZBUF - 1)) {
+		if (decomp && zbuf.avail_in == 0 && error == Z_STREAM_END) {
+			/* Done. */
+			break;
+		} else if (!decomp && error == Z_STREAM_END) {
+			/* Done. */
+			break;
+		} else if (zbuf.avail_out == 0) {
 			/* we need more output space, allocate size */
 			buf[i].out = malloc((u_long) size,
 			    M_CRYPTO_DATA, M_NOWAIT);
@@ -130,11 +134,12 @@ deflate_global(data, size, decomp, out)
 			buf[i].flag = 1;
 			zbuf.avail_out = buf[i].size;
 			i++;
-		} else
+		} else {
+			/* Unexpect result. */
 			goto bad;
+		}
 	}
 
-end:
 	result = count = zbuf.total_out;
 
 	*out = malloc((u_long) result, M_CRYPTO_DATA, M_NOWAIT);


More information about the svn-src-all mailing list