Skip to content

Commit b7d36ef

Browse files
committed
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.
1 parent a086724 commit b7d36ef

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/zstream.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@
1414
#define ZSTREAM_BUFFER_SIZE (1024 * 1024)
1515
#define ZSTREAM_BUFFER_MIN_EXTRA 8
1616

17-
static int zstream_seterr(git_zstream *zs)
17+
GIT_INLINE(int) zstream_seterr(git_zstream *zs)
1818
{
19-
if (zs->zerr == Z_OK || zs->zerr == Z_STREAM_END)
19+
switch (zs->zerr) {
20+
case Z_OK:
21+
case Z_STREAM_END:
22+
case Z_BUF_ERROR: /* not fatal; we retry with a larger buffer */
2023
return 0;
21-
22-
if (zs->zerr == Z_MEM_ERROR)
24+
case Z_MEM_ERROR:
2325
giterr_set_oom();
24-
else if (zs->z.msg)
25-
giterr_set_str(GITERR_ZLIB, zs->z.msg);
26-
else
27-
giterr_set(GITERR_ZLIB, "unknown compression error");
26+
break;
27+
default:
28+
if (zs->z.msg)
29+
giterr_set_str(GITERR_ZLIB, zs->z.msg);
30+
else
31+
giterr_set(GITERR_ZLIB, "unknown compression error");
32+
}
2833

2934
return -1;
3035
}
@@ -119,8 +124,8 @@ int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream)
119124
else
120125
zstream->zerr = deflate(&zstream->z, zflush);
121126

122-
if (zstream->zerr == Z_STREAM_ERROR)
123-
return zstream_seterr(zstream);
127+
if (zstream_seterr(zstream))
128+
return -1;
124129

125130
out_used = (out_queued - zstream->z.avail_out);
126131
out_remain -= out_used;

0 commit comments

Comments
 (0)