summaryrefslogtreecommitdiff
path: root/src/zstream.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-12-12 12:24:11 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2017-12-20 16:08:01 +0000
commitb7d36ef4a644c69c37e64c7c813546a68264b924 (patch)
tree157d9d3ed7162925ac2ff2a3174ea96b46a5c5e3 /src/zstream.c
parenta08672425d75a9a237d6282a53023faae091839b (diff)
downloadlibgit2-b7d36ef4a644c69c37e64c7c813546a68264b924.tar.gz
zstream: treat `Z_BUF_ERROR` as non-fatal
zlib will return `Z_BUF_ERROR` whenever there is more input to inflate or deflate than there is output to store the result. This is normal for us as we iterate through the input, particularly with very large input buffers.
Diffstat (limited to 'src/zstream.c')
-rw-r--r--src/zstream.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/zstream.c b/src/zstream.c
index 4895bdb16..1c9d506b1 100644
--- a/src/zstream.c
+++ b/src/zstream.c
@@ -14,17 +14,22 @@
#define ZSTREAM_BUFFER_SIZE (1024 * 1024)
#define ZSTREAM_BUFFER_MIN_EXTRA 8
-static int zstream_seterr(git_zstream *zs)
+GIT_INLINE(int) zstream_seterr(git_zstream *zs)
{
- if (zs->zerr == Z_OK || zs->zerr == Z_STREAM_END)
+ switch (zs->zerr) {
+ case Z_OK:
+ case Z_STREAM_END:
+ case Z_BUF_ERROR: /* not fatal; we retry with a larger buffer */
return 0;
-
- if (zs->zerr == Z_MEM_ERROR)
+ case Z_MEM_ERROR:
giterr_set_oom();
- else if (zs->z.msg)
- giterr_set_str(GITERR_ZLIB, zs->z.msg);
- else
- giterr_set(GITERR_ZLIB, "unknown compression error");
+ break;
+ default:
+ if (zs->z.msg)
+ giterr_set_str(GITERR_ZLIB, zs->z.msg);
+ else
+ giterr_set(GITERR_ZLIB, "unknown compression error");
+ }
return -1;
}
@@ -119,8 +124,8 @@ int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream)
else
zstream->zerr = deflate(&zstream->z, zflush);
- if (zstream->zerr == Z_STREAM_ERROR)
- return zstream_seterr(zstream);
+ if (zstream_seterr(zstream))
+ return -1;
out_used = (out_queued - zstream->z.avail_out);
out_remain -= out_used;