Issues

ZF-10215: decodeGzip not decoding properly (workaround provided)

Description

I was puzzled by why I couldn't get the body of http://rss1.smashingmagazine.com/feed.

Turns out decodeGzip() was ignoring some gzip material that caused gzinflate() to crash. Presumably, substr($body, 10) was passing some garbage to gzinflate().

I then learned about the gzBody() function in http://php.net/manual/en/…, which solved the problem for me.

As an incremental workaround, I have replaced the final line "return gzinflate(substr($body, 10));" with the code below.

Note that it only affects the result of decodeGzip() if gzinflate() can't inflate, so it should be compatible with older versions.

== BEGIN WORKAROUND - REPLACE RETURN LINE WITH THIS ==



$decodedBody = gzinflate(substr($body, 10)); // Zend originally returned this (without @)
if ($decodedBody === false) {

    if (substr($body,0,3) == "\x1f\x8b\x08") { 
        $i   = 10;
        $flg = ord(substr($body,3,1));
        if ($flg > 0) {
            if ($flg & 4){ 
                list($xlen) = unpack('v', substr($body, $i, 2));
                $i = $i + 2 + $xlen;
            }
            if ($flg&8) $i = strpos($body, "\0", $i) + 1; 
            if ($flg&16) $i = strpos($body, "\0", $i) + 1; 
            if ($flg&2) $i = $i + 2; 
        } 
        $decodedBody = gzinflate(substr($body, $i, -8)); 
    } else {
        $decodedBody = false; 
    }
} // if !decodedBody
        
return $decodedBody;

== END OF WORKAROUND ==

Comments

tried to format the "patch"