Issues

ZF-5794: Zend_Feed_Rss Feedburner

Description

Hi,

I'm trying to import a feed from FeedBurner with Zend_Feed_Rss and i'm getting following error: Invalid chunk size "" unable to read chunked body

Valid Feed: http://validator.w3.org/feed/check.cgi/…


$channel = new Zend_Feed_Rss('http://feeds.feedburner.com/dso-nieuws-binnenland');

Error


Zend_Http_Client_Adapter_Exception Object
(
    [message:protected] => Invalid chunk size "" unable to read chunked body
    [string:private] => 
    [code:protected] => 0
    [file:protected] => /home/httpd/XX/library/Zend-1.7.4/Http/Client/Adapter/Socket.php
    [line:protected] => 257
    [trace:private] => Array
        (
            [0] => Array
                (
                    [file] => /home/httpd/XX/library/Zend-1.7.4/Http/Client.php
                    [line] => 845
                    [function] => read
                    [class] => Zend_Http_Client_Adapter_Socket
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

            [1] => Array
                (
                    [file] => /home/httpd/XX/library/Zend-1.7.4/Feed/Abstract.php
                    [line] => 78
                    [function] => request
                    [class] => Zend_Http_Client
                    [type] => ->
                    [args] => Array
                        (
                            [0] => GET
                        )

                )

Comments

Bug cause is incorrect string functions working on multibyte strings. In my case bug was reproduced on three conditions 1. mbstring overloading parameter = 2 2. importing rss feed have "Transfer-Encoding: chunked" header. 3 and encoding of importing rss feed is UTF-8

Hotfix for this bug is using mb_ functions for parsing chunked content; That is in my case (im using ZF 1.7.0):

file Zend/Http/Client/Adapter/Socket.php from line 266 and below


while ($left_to_read > 0) {
    $line = @fread($this->socket, $left_to_read);
    $chunk .= $line;
    
    // + sx patch
    if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload')))
        $left_to_read -= mb_strlen($line, 'iso-8859-1'); 
    else
        $left_to_read -= strlen($line);
    // - sx patch
    
    // Break if the connection ended prematurely
    if (feof($this->socket)) break;
}

file Zend/Http/Response.php from line 554 and below:


while (trim($body)) {
    if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
        require_once 'Zend/Http/Exception.php';
        throw new Zend_Http_Exception("Error parsing body - doesn't seem to be a chunked message");
    }
    
    // + sx patch
    $length = hexdec(trim($m[1]));
    if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))){
        $cut = mb_strlen($m[0], 'iso-8859-1');
        $decBody .= mb_substr($body, $cut, $length, 'iso-8859-1');
        $body = mb_substr($body, $cut + $length + 2, 'iso-8859-1');
    }else{
        $cut = strlen($m[0]);
        $decBody .= substr($body, $cut, $length);
        $body = substr($body, $cut + $length + 2);
    }
    // - sx patch
}

enjoy it and good luck!

Tested with 1.11dev, and appears to no longer be an issue.