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>
Junio C Hamano committed
Jun 10, 2011 at 10:45 UTC
5e86c1fb866ca4bc8d6e015ccbdafd114fd616fa
3 files changed
+17
-4
cache.h
+1
@@ -21,6 +21,7 @@
21
#endif
22
23
void git_inflate_init(z_streamp strm);
24
+void git_inflate_init_gzip_only(z_streamp strm);
25
void git_inflate_end(z_streamp strm);
26
int git_inflate(z_streamp strm, int flush);
27
http-backend.c
+1
-4
@@ -275,12 +275,9 @@ static void inflate_request(const char *prog_name, int out)
275
unsigned char in_buf[8192];
276
unsigned char out_buf[8192];
277
unsigned long cnt = 0;
278
- int ret;
278
279
memset(&stream, 0, sizeof(stream));
281
- ret = inflateInit2(&stream, (15 + 16));
282
- if (ret != Z_OK)
283
- die("cannot start zlib inflater, zlib err %d", ret);
280
+ git_inflate_init_gzip_only(&stream);
281
282
while (1) {
283
ssize_t n = xread(0, in_buf, sizeof(in_buf));
zlib.c
+15
@@ -32,6 +32,21 @@ void git_inflate_init(z_streamp strm)
32
strm->msg ? strm->msg : "no message");
33
}
34
35
+void git_inflate_init_gzip_only(z_streamp strm)
36
+{
37
+ /*
38
+ * Use default 15 bits, +16 is to accept only gzip and to
39
+ * yield Z_DATA_ERROR when fed zlib format.
40
+ */
41
+ const int windowBits = 15 + 16;
42
+ int status = inflateInit2(strm, windowBits);
43
+
44
+ if (status == Z_OK)
45
+ return;
46
+ die("inflateInit2: %s (%s)", zerr_to_string(status),
47
+ strm->msg ? strm->msg : "no message");
48
+}
49
+
50
void git_inflate_end(z_streamp strm)
51
{
52
int status = inflateEnd(strm);