зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
9e7e5ca372
Коммит
5e86c1fb86
1
cache.h
1
cache.h
|
@ -21,6 +21,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void git_inflate_init(z_streamp strm);
|
void git_inflate_init(z_streamp strm);
|
||||||
|
void git_inflate_init_gzip_only(z_streamp strm);
|
||||||
void git_inflate_end(z_streamp strm);
|
void git_inflate_end(z_streamp strm);
|
||||||
int git_inflate(z_streamp strm, int flush);
|
int git_inflate(z_streamp strm, int flush);
|
||||||
|
|
||||||
|
|
|
@ -275,12 +275,9 @@ static void inflate_request(const char *prog_name, int out)
|
||||||
unsigned char in_buf[8192];
|
unsigned char in_buf[8192];
|
||||||
unsigned char out_buf[8192];
|
unsigned char out_buf[8192];
|
||||||
unsigned long cnt = 0;
|
unsigned long cnt = 0;
|
||||||
int ret;
|
|
||||||
|
|
||||||
memset(&stream, 0, sizeof(stream));
|
memset(&stream, 0, sizeof(stream));
|
||||||
ret = inflateInit2(&stream, (15 + 16));
|
git_inflate_init_gzip_only(&stream);
|
||||||
if (ret != Z_OK)
|
|
||||||
die("cannot start zlib inflater, zlib err %d", ret);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
ssize_t n = xread(0, in_buf, sizeof(in_buf));
|
ssize_t n = xread(0, in_buf, sizeof(in_buf));
|
||||||
|
|
15
zlib.c
15
zlib.c
|
@ -32,6 +32,21 @@ void git_inflate_init(z_streamp strm)
|
||||||
strm->msg ? strm->msg : "no message");
|
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)
|
void git_inflate_end(z_streamp strm)
|
||||||
{
|
{
|
||||||
int status = inflateEnd(strm);
|
int status = inflateEnd(strm);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче