mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
Merge remote-tracking branch 'origin/topic/seth/deflate-missing-headers-fix'
I've changed the dynamic allocation of the unzipbuf back to stack allocation, hope I'm not not missing the reason for doing that ... * origin/topic/seth/deflate-missing-headers-fix: Fixes an issue with missing zlib headers on deflated HTTP content. BIT-1399 #merged
This commit is contained in:
commit
264a824fcc
6 changed files with 72 additions and 26 deletions
|
@ -22,10 +22,9 @@ ZIP_Analyzer::ZIP_Analyzer(Connection* conn, bool orig, Method arg_method)
|
|||
zip->next_in = 0;
|
||||
zip->avail_in = 0;
|
||||
|
||||
// "15" here means maximum compression. "32" is a gross overload
|
||||
// hack that means "check it for whether it's a gzip file". Sheesh.
|
||||
zip_status = inflateInit2(zip, 15 + 32);
|
||||
if ( zip_status != Z_OK )
|
||||
// "32" is a gross overload hack that means "check it
|
||||
// for whether it's a gzip file". Sheesh.
|
||||
if ( inflateInit2(zip, MAX_WBITS + 32) != Z_OK )
|
||||
{
|
||||
Weird("inflate_init_failed");
|
||||
delete zip;
|
||||
|
@ -56,38 +55,63 @@ void ZIP_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
|
|||
static unsigned int unzip_size = 4096;
|
||||
Bytef unzipbuf[unzip_size];
|
||||
|
||||
int allow_restart = 1;
|
||||
|
||||
zip->next_in = (Bytef*) data;
|
||||
zip->avail_in = len;
|
||||
|
||||
do
|
||||
Bytef *orig_next_in = zip->next_in;
|
||||
size_t orig_avail_in = zip->avail_in;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
zip->next_out = unzipbuf;
|
||||
zip->avail_out = unzip_size;
|
||||
|
||||
zip_status = inflate(zip, Z_SYNC_FLUSH);
|
||||
|
||||
if ( zip_status != Z_STREAM_END &&
|
||||
zip_status != Z_OK &&
|
||||
zip_status != Z_BUF_ERROR )
|
||||
if ( zip_status == Z_STREAM_END ||
|
||||
zip_status == Z_OK )
|
||||
{
|
||||
allow_restart = 0;
|
||||
|
||||
int have = unzip_size - zip->avail_out;
|
||||
if ( have )
|
||||
ForwardStream(have, unzipbuf, IsOrig());
|
||||
|
||||
if ( zip_status == Z_STREAM_END )
|
||||
{
|
||||
inflateEnd(zip);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( zip->avail_in == 0 )
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
else if ( allow_restart && zip_status == Z_DATA_ERROR )
|
||||
{
|
||||
// Some servers seem to not generate zlib headers,
|
||||
// so this is an attempt to fix and continue anyway.
|
||||
inflateEnd(zip);
|
||||
|
||||
if ( inflateInit2(zip, -MAX_WBITS) != Z_OK )
|
||||
{
|
||||
Weird("inflate_init_failed");
|
||||
return;
|
||||
}
|
||||
|
||||
zip->next_in = orig_next_in;
|
||||
zip->avail_in = orig_avail_in;
|
||||
allow_restart = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Weird("inflate_failed");
|
||||
inflateEnd(zip);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
int have = unzip_size - zip->avail_out;
|
||||
if ( have )
|
||||
ForwardStream(have, unzipbuf, IsOrig());
|
||||
|
||||
if ( zip_status == Z_STREAM_END )
|
||||
{
|
||||
inflateEnd(zip);
|
||||
delete zip;
|
||||
zip = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
zip_status = Z_OK;
|
||||
}
|
||||
while ( zip->avail_out == 0 );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue