On 11/10/62 06:18, 吕涛 wrote:
Hi, there is an inconsistency between sqlite implementation and documentation of zlib API deflate in the file /ext/misc/zipfile.c:1003.1000 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); 1001 res = deflate(&str, Z_FINISH); 1002 1003 if( res==Z_STREAM_END ){ 1004 *ppOut = aOut; 1005 *pnOut = (int)str.total_out; 1006 }else{ 1007 sqlite3_free(aOut); 1008 *pzErr = sqlite3_mprintf("zipfile: deflate() error"); 1009 rc = SQLITE_ERROR; 1010 } 1011 deflateEnd(&str); According to the description of zlib API deflate, when calling deflate with parameter Z_FINISH, it must be called again with much more output space if returning Z_OK or Z_BUF_ERROR. However, in the implementation of sqlite, it didn't.
Thanks for looking into this. I think it's Ok because the output buffer is always at least compressBound() bytes in size.
Technically the maximum size of an output buffer populated by deflate() is deflateBytes(). But looking at the implementations, compressBound() is always larger than the equivalent deflateBound() value would be for the way we're configuring deflate(). Still, to be correct, it's now changed to use deflateBound() to size the buffer here:
https://sqlite.org/src/info/f5ee30426e8876e70304 Dan.
The description of zlib API deflate is shown as bellow: If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this function must be called again with Z_FINISH and more output space (updated avail_out) but no more input data, until it returns with Z_STREAM_END or an error. After deflate has returned Z_STREAM_END, the only possible operations on the stream are deflateReset or deflateEnd. _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

