cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: [PATCH] broken servers send bad deflate streams

From: Paul Querna <chip_at_corelands.com>
Date: Tue, 25 Apr 2006 13:36:03 -0700

Daniel Stenberg wrote:
> Hi
>
> As has been reported before several times and as was once attempted to
> be fixed (although the author vanished before the patch was in a
> sensible state), some servers sends bad deflate stream that lacks the
> header.
>
> I got a URL privately that returns such a content and I wrote up a patch
> after reading some Firefox code that does the similar work-around (see
> patch for URL to the Firefox code).
>
> I'm not sure this patch is working perfectly so I would like someone who
> experiences this problem and knows how the content should look like to
> see if this patch fixes the problem or if it needs some further tweaks.

Attached is an alternative patch, that does go through the trouble of
faking the header, and instead twists around with the window size
toggles, and seems to fix all the test cases I have found.

-Paul

Index: content_encoding.c
===================================================================
--- content_encoding.c (revision 8484)
+++ content_encoding.c (revision 8645)
@@ -87,7 +87,10 @@
 inflate_stream(struct SessionHandle *data,
                struct Curl_transfer_keeper *k)
 {
+ int allow_restart = 1;
   z_stream *z = &k->z; /* zlib state structure */
+ uInt nread = z->avail_in;
+ Bytef *orig_in = z->next_in;
   int status; /* zlib status */
   CURLcode result = CURLE_OK; /* Curl_client_write status */
   char *decomp; /* Put the decompressed data here. */
@@ -133,6 +136,16 @@
         return result;
       }
     }
+ else if (allow_restart && status == Z_DATA_ERROR) {
+ inflateReset(z);
+ if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
+ return process_zlib_error(data, z);
+ }
+ z->next_in = orig_in;
+ z->avail_in = nread;
+ allow_restart = 0;
+ continue;
+ }
     else { /* Error; exit loop, handle below */
       free(decomp);
       return exit_zlib(z, &k->zlib_init, process_zlib_error(data, z));
Received on 2006-04-25