From: Fabian Keil Date: Fri, 8 Jul 2011 13:27:56 +0000 (+0000) Subject: In compress_buffer(), add some room for the zlib overhead X-Git-Tag: v_3_0_18~180 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=fc95f97a7020e56f373bf744715d73afe58b773a In compress_buffer(), add some room for the zlib overhead If the entropy is high enough, the data may not be compressable, or at least not compressable enough to make room for the header. If the compression level is 0, the "compressed" is guaranteed to take more room than the "uncompressed" data. --- diff --git a/cgi.c b/cgi.c index 028a798d..55ef1e9b 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.137 2011/07/03 17:55:23 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.138 2011/07/08 13:27:31 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -1507,9 +1507,20 @@ static void get_locale_time(char *buf, size_t buffer_size) char *compress_buffer(char *buffer, size_t *buffer_length, int compression_level) { char *compressed_buffer; - size_t new_length = *buffer_length; + size_t new_length; assert(-1 <= compression_level && compression_level <= 9); + /* + * If the compression level is 0 or if the entropy + * is high, the "compressing" data will take more + * room then the uncompressed data due to the zlib + * overhead. + * + * XXX: The overhead isn't constant and 30 bytes + * may not be enough for everybody + */ + new_length = *buffer_length + 30; + compressed_buffer = malloc(new_length); if (NULL == compressed_buffer) {