Skip to content

Commit 24eacab

Browse files
authored
Merge pull request libgit2#5599 from libgit2/ethomson/zlib
zstream: handle Z_BUF_ERROR appropriately in get_output_chunk
2 parents 8a24ee8 + 4d4befa commit 24eacab

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/pack.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,10 @@ static int packfile_unpack_compressed(
844844
unsigned int window_len;
845845
unsigned char *in;
846846

847-
in = pack_window_open(p, mwindow, *position, &window_len);
847+
if ((in = pack_window_open(p, mwindow, *position, &window_len)) == NULL) {
848+
error = -1;
849+
goto out;
850+
}
848851

849852
if ((error = git_zstream_set_input(&zstream, in, window_len)) < 0 ||
850853
(error = git_zstream_get_output_chunk(data + total, &bytes, &zstream)) < 0) {
@@ -854,9 +857,12 @@ static int packfile_unpack_compressed(
854857

855858
git_mwindow_close(mwindow);
856859

860+
if (!bytes)
861+
break;
862+
857863
*position += window_len - zstream.in_len;
858864
total += bytes;
859-
} while (total < size);
865+
} while (!git_zstream_eos(&zstream));
860866

861867
if (total != size || !git_zstream_eos(&zstream)) {
862868
git_error_set(GIT_ERROR_ZLIB, "error inflating zlib stream");

0 commit comments

Comments
 (0)