Date: Sat, 28 Nov 2009 17:44:58 +0000 (UTC) From: "Bjoern A. Zeeb" <bz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r199887 - head/sys/opencrypto Message-ID: <200911281744.nASHiw7e062518@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bz Date: Sat Nov 28 17:44:57 2009 New Revision: 199887 URL: http://svn.freebsd.org/changeset/base/199887 Log: 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 npt seem to cope well with, resulting in errors when uncompressing exactly fills the outbut buffer without a Z_STREAM_END and a successive call returns an error. MFC after: 6 days Modified: head/sys/opencrypto/deflate.c Modified: head/sys/opencrypto/deflate.c ============================================================================== --- head/sys/opencrypto/deflate.c Sat Nov 28 17:33:19 2009 (r199886) +++ head/sys/opencrypto/deflate.c Sat Nov 28 17:44:57 2009 (r199887) @@ -138,8 +138,8 @@ deflate_global(data, size, decomp, out) 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) { /* * Unfortunately we are limited to 5 arguments, @@ -153,9 +153,13 @@ deflate_global(data, size, decomp, out) zbuf.state->dummy, zbuf.total_out); 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); @@ -170,6 +174,7 @@ deflate_global(data, size, decomp, out) zbuf.avail_out = buf[i].size; i++; } else { + /* Unexpect result. */ /* * Unfortunately we are limited to 5 arguments, * thus, again, use two probes. @@ -184,7 +189,6 @@ deflate_global(data, size, decomp, out) } } -end: result = count = zbuf.total_out; *out = malloc((u_long) result, M_CRYPTO_DATA, M_NOWAIT);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200911281744.nASHiw7e062518>