From:             phpbug at tore dot cc
Operating system: Solaris 10
PHP version:      5.0.2
PHP Bug Type:     Strings related
Bug description:  function strlen miscounts

Description:
------------
I have discoverd that a large amount of the php-scripts are using 'strlen'
to count length of arbitrary strings.
strlen can not cope with arbitrary strings!

Code like will only show garbage values:
$a = fread($binaryfile,$count);
print strlen($a) . " number of bytes is read from 
                                the binary file";


Reproduce code:
---------------
<?php
$s='';
print "<html>\n";
for($i=142;$i<256;$i++){
        $s.=pack("C",$i);
        $result = count_chars($s, 0);
        $l=0;
        for ($j=0; $j < 256; $j++) {
                $l+=$result[$j];
        }
        print "<br>The variable s has the length: " .
                strlen($s) . " (actual length) " . $l . "</br>\n";
}
print "</html>\n";
?>

Expected result:
----------------
The variable s has the length: 1 (actual length) 1
The variable s has the length: 1 (actual length) 2
The variable s has the length: 2 (actual length) 3
The variable s has the length: 3 (actual length) 4
The variable s has the length: 4 (actual length) 5
The variable s has the length: 5 (actual length) 6
The variable s has the length: 6 (actual length) 7
The variable s has the length: 7 (actual length) 8
The variable s has the length: 8 (actual length) 9
The variable s has the length: 9 (actual length) 10
The variable s has the length: 10 (actual length) 11
The variable s has the length: 11 (actual length) 12
.
.
.
The variable s has the length: 64 (actual length) 111
The variable s has the length: 65 (actual length) 112
The variable s has the length: 65 (actual length) 113
The variable s has the length: 66 (actual length) 114

Actual result:
--------------
The variable s has the length: 1 (actual length) 1
The variable s has the length: 2 (actual length) 2
The variable s has the length: 3 (actual length) 3
The variable s has the length: 4 (actual length) 4
The variable s has the length: 5 (actual length) 5
The variable s has the length: 6 (actual length) 6
The variable s has the length: 7 (actual length) 7
The variable s has the length: 8 (actual length) 8
The variable s has the length: 9 (actual length) 9
The variable s has the length: 10 (actual length) 10
The variable s has the length: 11 (actual length) 11
The variable s has the length: 12 (actual length) 12
.
.
.
The variable s has the length: 111 (actual length) 111
The variable s has the length: 112 (actual length) 112
The variable s has the length: 113 (actual length) 113
The variable s has the length: 114 (actual length) 114

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

Reply via email to