Fix an endless loop in the deflate bucket with the truncated input.

The endless loop can be triggered by how this bucket has been handling
Z_BUF_ERROR, which is returned when zlib can't move forward, either when
it requires more output space (1), or there is no more input (2).

We have been handling such errors by resetting the output buffer and
continuing, but this only handles (1).  In case of the truncated input,
we are dealing with (2), and resetting the output buffer doesn't help —
and that has been causing the endless loop.  Fix this by separately
handling the case with Z_BUF_ERROR and no more input.

* buckets/deflate_buckets.c
  (serf_deflate_refill): Handle a case when we hit the end of input
   stream and zlib can't continue, even though there's enough output
   space.  If that happens, return an error.

* test/test_buckets.c
  (test_deflate_bucket_truncated_data): New test, fails without the fix.
  (test_buckets): Add new test.


git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1805301 13f79535-47bb-0310-9956-ffa450edef68
2 files changed