ID: 31324
User updated by: phpbug at tore dot cc
Reported By: phpbug at tore dot cc
Status: Open
Bug Type: Strings related
Operating System: Solaris 10
PHP Version: 5.0.2
New Comment:
My configuration:
./configure --with-apxs=/opt/csw/apache/bin/apxs --with-mod_charset
--with-openssl=/opt/csw --enable-ftp --with-imap-ssl
--with-jpeg=/usr/csw/lib --with-mysql=/opt/sfw/mysql --with-pgsql
--enable-mbstr-enc-trans --enable-mbstring --enable-mbregex
--with-tiff=/usr/sfc/lib --enable-inline-optimization
--with-imap=/mnt/slask/src/imap-2002 --with-java=/usr/j2se
--with-ming=/usr/local --with-orc8=/opt/oracle
--with-gettext --with-xml --with-dom --with-zlib --enable-cli
--enable-zend-multibyte --with-mod_charset --enable-gd-jis-conv
--disable-libxml
Previous Comments:
------------------------------------------------------------------------
[2004-12-28 18:36:13] phpbug at tore dot cc
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 this bug report at http://bugs.php.net/?id=31324&edit=1