[zlib_bench] check deflate consumed all input

zlib_compress deflate() should consume all the input data. Add a check
and fail the deflation if there is unconsumed input data when the zlib deflate() call returns.

What about inflate()? zlib_bench knows the expected length of the data
(it is the original input length) and fails with a Z_DATA_ERROR if the zlib_uncompress inflate() output data length does not match.

Bug: 798943
Change-Id: Ibdc9752754a52343ea6139ce9cc5a99c2a0a57a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3630105
Auto-Submit: Noel Gordon <noel@chromium.org>
Reviewed-by: Chris Blume <cblume@chromium.org>
Commit-Queue: Chris Blume <cblume@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1003565}
GitOrigin-RevId: 4cc4f4c0086c2e5ad52bff6be7e2430b72ebcba9
diff --git a/contrib/bench/zlib_bench.cc b/contrib/bench/zlib_bench.cc
index 3d99646..097f14f 100644
--- a/contrib/bench/zlib_bench.cc
+++ b/contrib/bench/zlib_bench.cc
@@ -146,6 +146,8 @@
   stream.avail_in = (uInt)input_size;
   result = deflate(&stream, Z_FINISH);
+  if (stream.avail_in > 0)
+    error_exit("compress: input was not consumed", Z_DATA_ERROR);
   if (result == Z_STREAM_END)
     output_size = stream.total_out;
   result |= deflateEnd(&stream);