On 07/29/2007 10:35 AM, wrote:
> Author: niq
> Date: Sun Jul 29 01:35:56 2007
> New Revision: 560689
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=560689
> Log:
> Fix protocol handling in mod_deflate input filter
> PR 23287
> 
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/modules/filters/mod_deflate.c
> 

> Modified: httpd/httpd/trunk/modules/filters/mod_deflate.c
> URL: 
> http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_deflate.c?view=diff&rev=560689&r1=560688&r2=560689
> ==============================================================================
> --- httpd/httpd/trunk/modules/filters/mod_deflate.c (original)
> +++ httpd/httpd/trunk/modules/filters/mod_deflate.c Sun Jul 29 01:35:56 2007
> @@ -665,22 +665,52 @@
>              return ap_get_brigade(f->next, bb, mode, block, readbytes);
>          }
>  
> -        /* Let's see what our current Content-Encoding is.
> -         * If gzip is present, don't gzip again.  (We could, but let's not.)
> +        /* Check whether request body is gzipped.
> +         *
> +         * If it is, we're transforming the contents, invalidating
> +         * some request headers including Content-Encoding.
> +         *
> +         * If not, we just remove ourself.
>           */
>          encoding = apr_table_get(r->headers_in, "Content-Encoding");
> -        if (encoding) {
> +        if (encoding && *encoding) {
>              const char *tmp = encoding;
>  
> -            token = ap_get_token(r->pool, &tmp, 0);
> -            while (token && token[0]) {
> -                if (!strcasecmp(token, "gzip")) {
> -                    found = 1;
> -                    break;
> -                }
> -                /* Otherwise, skip token */
> -                tmp++;
> +            /* check the usual/simple case first */
> +            if (!strcasecmp(encoding, "gzip")) {
> +                found = 1;
> +                apr_table_unset(r->headers_in, "Content-Encoding");
> +            }
> +            else {
>                  token = ap_get_token(r->pool, &tmp, 0);
> +                while (token && token[0]) {
> +                    if (!strcasecmp(token, "gzip")) {
> +                        char *new_encoding = apr_pstrdup(r->pool, encoding);
> +                        char *ptr = ap_strstr(new_encoding, token);
> +                        size_t sz = 5*sizeof(char);
> +                        if (ptr == new_encoding) {
> +                            /* remove "gzip:" at start */
> +                            memmove(ptr, ptr+sz, sz);

Maybe I am missing the point, but if gzip is at the start why moving memory and 
not
simply increasing new_encoding by 5?

> +                        }
> +                        else {
> +                            /* remove ":gzip" as found */
> +                            memmove(ptr-sizeof(char), ptr+4*sizeof(char), 
> sz);

Is this correct? memmove maybe bcopy on platforms where no memmove is available 
and as
I understand the man pages of memmove and bcopy it would only copy sz bytes 
from behind
gzip to the old position of the gzip string. What if you have

Content-Encoding: compress:gzip:deflate

(OK, a silly case, but still valid).

As far as I understand this would result in
compress:defl:deflate

And BTW, as the order of the encodings in Content-Encoding must be the order in 
which they have been
applied, don't we need to ensure that gzip needs to be at the *end* of the 
content encoding string, as
we have to decode things in the reverse order?
Otherwise we would try to decode a gzip encoding when there is still another 
encoding on top of gzip.


Regards

RĂ¼diger

Reply via email to