Possible bug in mb.inc.php Possible bug in mb.inc.php
 

News:

CPG Release 1.6.27
change DB IP storage fields to accommodate IPv6 addresses
remove use of E_STRICT (PHP 8.4 deprecated)
update README to reflect new website
align code with new .com CPG website
correct deprecation in captcha

Main Menu

Possible bug in mb.inc.php

Started by Pit, December 05, 2005, 11:54:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Pit

There seems to be a bug in include/mb.inc.php function mb_substr():

While trying to bridge cpg to ipb I have noticed that all group names of ipb have been imported only with the first character. This happened on a server where I didn't have activated mbstring library in php.ini. Testing the error in my local environment I found the bug in mb.inc.php.

In the original code of mb_substr you call array_slice always with parameter length (here $end) even when that parameter is null. In my php installation (4.4.1)  array_slice returns only the $start element of the array instead of the entire rest of it.

        function mb_substr($str, $start, $end=null) {
                global $mb_utf8_regex;
                preg_match_all("#$mb_utf8_regex".'|[\x00-\x7F]#', $str, $str);
                $str = array_slice($str[0], $start, $end);
                return implode('', $str);
        }


To avoid this behavior I have had to modify the function:
        function mb_substr($str, $start, $end=null) {
                global $mb_utf8_regex;
                preg_match_all("#$mb_utf8_regex".'|[\x00-\x7F]#', $str, $str);
                if ($end == null)
                    $str = array_slice($str[0], $start);
                else
                    $str = array_slice($str[0], $start, $end);
                return implode('', $str);
        }


Perhaps you can verify this as a bug.
I do not code for or support Invisionboard 2.x