From:             mcorne at yahoo dot com
Operating system: RedHat Linux x86-64
PHP version:      5.2.3
PHP Bug Type:     mbstring related
Bug description:  mb_substr error if length = PHP_INT_MAX

Description:
------------
mb_substr("\x44\xCC\x87", 0, PHP_INT_MAX, 'UTF-8') only captures the first
character on linux 64-bit instead of returning the whole string.
Note that this works fine on Windows XP and Linux 32-bit.

Reproduce code:
---------------
function substring($string, $length)
{
    $substr = mb_substr($string, 0, $length , 'UTF-8');
    $length = strlen($substr);
    $chars = $length? unpack("C{$length}chars", $substr) : array();
    $decs = array_map('dechex', $chars);
    return array($substr, $decs);
}

$test['string'] = "\x44\xCC\x87";
$test['utf8'] = '\x44\xCC\x87';
$test['unicode'] = '\u0044\u0307';
$test['PHP_INT_MAX'] = PHP_INT_MAX;
$test['php_int_max'] = substring($test['string'], PHP_INT_MAX);
$test['9999'] = substring($test['string'], 9999);

print_r($test);


Expected result:
----------------
Array
(
    [string] => Ḋ
    [utf8] => \x44\xCC\x87
    [unicode] => \u0044\u0307
    [PHP_INT_MAX] => 2147483647
    [php_int_max] => Array
        (
            [0] => Ḋ
            [1] => Array
                (
                    [chars1] => 44
                    [chars2] => cc
                    [chars3] => 87
                )

        )

    [9999] => Array
        (
            [0] => Ḋ
            [1] => Array
                (
                    [chars1] => 44
                    [chars2] => cc
                    [chars3] => 87
                )

        )

)

Actual result:
--------------
Array
(
    [string] => Ḋ
    [utf8] => \x44\xCC\x87
    [unicode] => \u0044\u0307
    [PHP_INT_MAX] => 2147483647
    [php_int_max] => Array
        (
            [0] => D
            [1] => Array
                (
                    [chars1] => 44
                )

        )

    [9999] => Array
        (
            [0] => Ḋ
            [1] => Array
                (
                    [chars1] => 44
                    [chars2] => cc
                    [chars3] => 87
                )

        )

)

-- 
Edit bug report at http://bugs.php.net/?id=42101&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42101&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42101&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42101&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42101&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42101&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42101&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42101&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42101&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42101&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42101&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42101&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42101&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42101&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42101&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42101&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42101&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42101&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42101&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42101&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42101&r=mysqlcfg

Reply via email to