cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem with CONTENT-ENCODING

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 12 Dec 2005 11:51:30 -0800

On Mon, Dec 12, 2005 at 08:50:01PM +0200, Dobromir Velev wrote:
> Here is a small patch that fixes the problem with the missing deflate header
> in the IIS response. It checks the first byte of the content and if it
> doesn't look like a header it tells zlib inflate() to process the raw deflate
> data without looking for headers.
>
> --- content_encoding.c 2005-03-31 10:02:03.000000000 +0300
> +++ content_encoding.new.c 2005-12-12 20:29:23.389573722 +0200
> @@ -149,14 +149,21 @@
> z_stream *z = &k->z; /* zlib state structure */
>
> /* Initialize zlib? */
> - if (k->zlib_init == ZLIB_UNINIT) {
> + if (k->zlib_init == ZLIB_UNINIT && nread) {
> z->zalloc = (alloc_func)Z_NULL;
> z->zfree = (free_func)Z_NULL;
> z->opaque = 0;
> z->next_in = NULL;
> z->avail_in = 0;
> - if (inflateInit(z) != Z_OK)
> - return process_zlib_error(data, z);
> + if((k->str[0] & 0xf) != Z_DEFLATED){
> + if(inflateInit2(z,-MAX_WBITS) != Z_OK)
> + return process_zlib_error(data, z);
> + }
> + else{
> + if(inflateInit(z) != Z_OK)
> + return process_zlib_error(data, z);
> + }
> +
> k->zlib_init = ZLIB_INIT;
> }

This patch will probably cause a crash if Curl_unencode_deflate_write
is ever called with nread==0. I'm not sure if that will ever happen,
but I suppose it could if the TCP segment ends right after the HTTP
headers and before the first byte of data. In any case, this makes the
code more brittle. Also, the if((k->str[0] & 0xf) != Z_DEFLATED) hack
should be well commented so the next maintainer understands the reason
for the brokenness.

> While testing it I encountered one more problem with broken server encoding.
> Some server when asked explicitly for deflate encoding will respond with
> "Content-encoding: deflate" header but will GZIP encode the data so the
> decoding will fail.
>
> This is definitely not a curl issue but I just wanted to let you know about
> it.

I wasn't aware of this issue. Do you know which server does this? Have
you reported it to the maintainer?

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2005-12-12