tor_zlib_process fails when trying to finish with no input or output bytes.
zlib reports Z_BUF_ERROR when it is out of input or out of output. Currently, we handle that with:
case Z_BUF_ERROR: if (state->stream.avail_in == 0) return TOR_ZLIB_OK; return TOR_ZLIB_BUF_FULL;
But that's wrong -- if avail_in is 0, but finish is set, then we are trying to finalize the stream, and we really do have something to write. That test should be
state->stream.avail_in == 0 && !finish)
Marking this for 0.2.5 even though I am pretty sure this can never actually happen with the way write_to_buf_zlib works: write_to_buf_zlib ensures that we are never trying to write into a completely empty buffer, and zlib says "Z_OK" if you give it even one byte to write into.