From bd4992435ca8343cca0b34af13cf6da331a357f8 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 13 Apr 2024 14:04:18 +0200 Subject: Add proper parsing for the gzip content encoding --- ot_fullscrape.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'ot_fullscrape.c') diff --git a/ot_fullscrape.c b/ot_fullscrape.c index b147b6a..86b9e26 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c @@ -262,33 +262,36 @@ fprintf(stderr, "GZIP path\n"); if( deflate( &strm, Z_FINISH ) < Z_OK ) fprintf( stderr, "deflate() failed while in fullscrape_make()'s endgame.\n" ); - if( !strm.avail_out ) { + iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base; + if (mutex_workqueue_pushchunked(taskid, &iovector) ) { + free(iovector.iov_base); + return mutex_bucket_unlock( bucket, 0 ); + } + + { unsigned int pending; int bits; deflatePending( &strm, &pending, &bits); pending += ( bits ? 1 : 0 ); - iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base; - if (mutex_workqueue_pushchunked(taskid, &iovector) ) { - free(iovector.iov_base); + if (pending) { + /* Allocate a fresh output buffer */ + iovector.iov_base = malloc( pending ); + iovector.iov_len = pending; + + if( !iovector.iov_base ) { + fprintf( stderr, "Problem with iovec_fix_increase_or_free\n" ); + deflateEnd(&strm); return mutex_bucket_unlock( bucket, 0 ); - } - /* Allocate a fresh output buffer */ - iovector.iov_base = malloc( pending ); - iovector.iov_len = pending; + } + strm.next_out = iovector.iov_base; + strm.avail_out = pending; + if( deflate( &strm, Z_FINISH ) < Z_OK ) + fprintf( stderr, "deflate() failed while in fullscrape_make()'s endgame.\n" ); - if( !iovector.iov_base ) { - fprintf( stderr, "Problem with iovec_fix_increase_or_free\n" ); - deflateEnd(&strm); - return mutex_bucket_unlock( bucket, 0 ); + if( mutex_workqueue_pushchunked(taskid, &iovector) ) + free(iovector.iov_base); } - strm.next_out = iovector.iov_base; - strm.avail_out = pending; - if( deflate( &strm, Z_FINISH ) < Z_OK ) - fprintf( stderr, "deflate() failed while in fullscrape_make()'s endgame.\n" ); - - if( mutex_workqueue_pushchunked(taskid, &iovector) ) - free(iovector.iov_base); } deflateEnd(&strm); -- cgit v1.2.3