From 5e86c1fb866ca4bc8d6e015ccbdafd114fd616fa Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 10 Jun 2011 10:45:29 -0700 Subject: 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 --- zlib.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'zlib.c') 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); -- cgit v1.2.1