PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTTP » HTTP_Download » Bug #7659

strlen() wrongly used to count number of bytes in data buffer

Details

Submitted2006-05-18 08:55 UTC
Fromdsier at g-point dot biz
StatusBogus
PackageHTTP_Download
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2006-05-18 08:55 UTC] dsier at g-point dot biz

Description:
------------
There are a few places where strlen() is used to count number of bytes in data buffer (Download::setData(), Download::flush()). This is wrong - strlen is not supposed to return number of bytes but number of characters in string.

Of course under normal circumstances those are equal, unless someone uses mb_internal_encoding() and sets internal encoding to some multibyte encoding (like UTF-8).

This may cause incorrect length to be reported by Content-Length and corrupted downloads.

Test script:
---------------
Possible workaround - use bytelen functions defined as:

function bytelen($data)
{
if (function_exists('mb_strlen')) {
return mb_strlen($data, 'latin1');
}

return strlen($data);
}

Note: "mb_internal_encoding" affects also other string-related functions (substr for example). So it can also affect other HTTP_Download methods like sendChunk() etc.

[2007-01-13 18:46 UTC] dsier at g-point dot biz

Bogus?

I don't think so. Here's example of code that gives wrong results (downloaded file is truncated). Tested with HTTP_Download 1.1.1.

http://www.g-point.biz/~dsier/bug.zip

Make sure that mbstring.func_overload is set to '2' in php.ini before you try it.