aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-06-10 10:45:29 -0700
committerJunio C Hamano <gitster@pobox.com>2011-06-10 10:51:02 -0700
commit5e86c1fb866ca4bc8d6e015ccbdafd114fd616fa (patch)
tree1acd628b6280d13d2dfae14d704edc1eb1544aa7
parent9e7e5ca372a0242069ff4e7eccecc7d5fe7ec385 (diff)
downloadgit-5e86c1fb866ca4bc8d6e015ccbdafd114fd616fa.tar.gz
git-5e86c1fb866ca4bc8d6e015ccbdafd114fd616fa.tar.xz
zlib: wrap inflateInit2 used to accept only for gzip format
http-backend.c uses inflateInit2() to tell the library that it wants to accept only gzip format. Wrap it in a helper function so that readers do not have to wonder what the magic numbers 15 and 16 are for. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--cache.h1
-rw-r--r--http-backend.c5
-rw-r--r--zlib.c15
3 files changed, 17 insertions, 4 deletions
diff --git a/cache.h b/cache.h
index ce73e1f09..50f09d05d 100644
--- a/cache.h
+++ b/cache.h
@@ -21,6 +21,7 @@
#endif
void git_inflate_init(z_streamp strm);
+void git_inflate_init_gzip_only(z_streamp strm);
void git_inflate_end(z_streamp strm);
int git_inflate(z_streamp strm, int flush);
diff --git a/http-backend.c b/http-backend.c
index c74cb03a7..ab5015d9d 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -275,12 +275,9 @@ static void inflate_request(const char *prog_name, int out)
unsigned char in_buf[8192];
unsigned char out_buf[8192];
unsigned long cnt = 0;
- int ret;
memset(&stream, 0, sizeof(stream));
- ret = inflateInit2(&stream, (15 + 16));
- if (ret != Z_OK)
- die("cannot start zlib inflater, zlib err %d", ret);
+ git_inflate_init_gzip_only(&stream);
while (1) {
ssize_t n = xread(0, in_buf, sizeof(in_buf));
diff --git a/zlib.c b/zlib.c
index be9d7e963..b613cbd75 100644
--- a/zlib.c
+++ b/zlib.c
@@ -32,6 +32,21 @@ void git_inflate_init(z_streamp strm)
strm->msg ? strm->msg : "no message");
}
+void git_inflate_init_gzip_only(z_streamp strm)
+{
+ /*
+ * Use default 15 bits, +16 is to accept only gzip and to
+ * yield Z_DATA_ERROR when fed zlib format.
+ */
+ const int windowBits = 15 + 16;
+ int status = inflateInit2(strm, windowBits);
+
+ if (status == Z_OK)
+ return;
+ die("inflateInit2: %s (%s)", zerr_to_string(status),
+ strm->msg ? strm->msg : "no message");
+}
+
void git_inflate_end(z_streamp strm)
{
int status = inflateEnd(strm);