#31324 [Fbk-Opn]: function strlen miscounts

2004-12-30 Thread phpbug at tore dot cc
 ID:   31324
 User updated by:  phpbug at tore dot cc
 Reported By:  phpbug at tore dot cc
-Status:   Feedback
+Status:   Open
 Bug Type: Strings related
 Operating System: Solaris 10
 PHP Version:  5.0.2
 New Comment:

I have traced down the trouble.
When multibyte strings support is complied in to php the internal
function 'strlen' is aliased to the function 'mb_strlen'.
mb_strlen counts the number of characters in the binary string
depending of what default encoding is used.

I have set the default chars to UTF-8 and SJIS (japanese) on my sparc
machine. That is why I only see it there.

Please remove the aliasing between strlen and mb_strlen!


Previous Comments:


[2004-12-30 10:55:57] [EMAIL PROTECTED]

It's impossible to extract that code from PHP, and as we don't have
access to a solaris machine we can not really debug this.



[2004-12-29 23:22:50] phpbug at tore dot cc

Are 64bit processors not supported by php?
Which machine architecture is 'my system'?

The php is compiled with gcc2 AND gcc3. With solaris 9 AND solaris 10.
The same trouble occurs.
So I need to have the code for 'strlen' in php extracted before I can
figure out where the source for the trouble is.

A simple C-program using string.h's strlen cause no troule at all.



[2004-12-29 21:42:53] [EMAIL PROTECTED]

Sounds like either a compiler or libc bug. I cannot replicate this on
my systems either.



[2004-12-29 19:13:28] phpbug at tore dot cc

I might add that I tried php-5.0.3 on an intel-based solaris 10 machine
and there were no problems with the strlen.



[2004-12-29 07:34:41] phpbug at tore dot cc

I have used gcc2 and gcc3 to compile.
The machine is a sparc.
The problem occurs on solaris 9 and solaris 10.
If you suspect that this is a solaris problem, can you extract the code
for 'strlen' in php. I could make some tests in C



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/31324

-- 
Edit this bug report at http://bugs.php.net/?id=31324edit=1


#31324 [Bgs-Csd]: function strlen miscounts

2004-12-30 Thread phpbug at tore dot cc
 ID:   31324
 User updated by:  phpbug at tore dot cc
 Reported By:  phpbug at tore dot cc
-Status:   Bogus
+Status:   Closed
 Bug Type: Strings related
 Operating System: Solaris 10
 PHP Version:  5.0.2
 New Comment:

I don't count 'php.ini' to documentation. Anyway thanks for the time.


Previous Comments:


[2004-12-30 14:44:56] [EMAIL PROTECTED]

Did you read the documentation?

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
;mbstring.func_overload = 0



[2004-12-30 14:33:30] phpbug at tore dot cc

I have traced down the trouble.
When multibyte strings support is complied in to php the internal
function 'strlen' is aliased to the function 'mb_strlen'.
mb_strlen counts the number of characters in the binary string
depending of what default encoding is used.

I have set the default chars to UTF-8 and SJIS (japanese) on my sparc
machine. That is why I only see it there.

Please remove the aliasing between strlen and mb_strlen!



[2004-12-30 10:55:57] [EMAIL PROTECTED]

It's impossible to extract that code from PHP, and as we don't have
access to a solaris machine we can not really debug this.



[2004-12-29 23:22:50] phpbug at tore dot cc

Are 64bit processors not supported by php?
Which machine architecture is 'my system'?

The php is compiled with gcc2 AND gcc3. With solaris 9 AND solaris 10.
The same trouble occurs.
So I need to have the code for 'strlen' in php extracted before I can
figure out where the source for the trouble is.

A simple C-program using string.h's strlen cause no troule at all.



[2004-12-29 21:42:53] [EMAIL PROTECTED]

Sounds like either a compiler or libc bug. I cannot replicate this on
my systems either.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/31324

-- 
Edit this bug report at http://bugs.php.net/?id=31324edit=1


#31324 [Opn]: function strlen miscounts

2004-12-29 Thread phpbug at tore dot cc
 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:

I might add that I tried php-5.0.3 on an intel-based solaris 10 machine
and there were no problems with the strlen.


Previous Comments:


[2004-12-29 07:34:41] phpbug at tore dot cc

I have used gcc2 and gcc3 to compile.
The machine is a sparc.
The problem occurs on solaris 9 and solaris 10.
If you suspect that this is a solaris problem, can you extract the code
for 'strlen' in php. I could make some tests in C



[2004-12-28 23:59:37] [EMAIL PROTECTED]

It still works fine for me on Linux. Which compiler did you use to
compile PHP (gcc or sun workshop), and what kind of platform do you
use? intel (32/64), sparc...



[2004-12-28 23:40:36] phpbug at tore dot cc

Sorry, my mistake!
It seems to work on one char long strings.
I made a better script (still avoiding loops...).

?php
$s=pack(C*,0x8e,0x8f);
$t=pack(C*,0x8e);
$u=pack(C*,0x8e,0x8f,0x90);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?


Result:
The variable s has the length: 1 
The variable t has the length: 1 
The variable u has the length: 2

The result should be:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

Since s=2 chars, t=1 char and u 3 chars long.

Lets try another test with 7 bit chars.

?php
$s=pack(C*,0x30,0x31);
$t=pack(C*,0x30);
$u=pack(C*,0x30,0x31,0x32);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?

Result:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

As expected. No problem with low values on the chars.



[2004-12-28 23:07:29] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Both in 4.3.10RC2, 5.0.3-dev, and 5.1.0-dev it prints as expected:
The variable s has the length: 1 (actual length) 1
So please try a snapshot.



[2004-12-28 21:57:50] phpbug at tore dot cc

How about:
?php
$s=pack(C,143);
$result = count_chars($s, 0);
print The variable s has the length:  .
   strlen($s) .  (actual length)  . $result[143] .  
   \n;
?
Gives printout:
The variable s has the length: 0 (actual length) 1

The 'pack' creates a bit-string with a length of 1 char.
The 'strlen' should should recognize it as a char with length 1. As you
can see below 'strlen' does not only miscalculates the string length for
the char 143.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/31324

-- 
Edit this bug report at http://bugs.php.net/?id=31324edit=1


#31324 [Bgs-Opn]: function strlen miscounts

2004-12-29 Thread phpbug at tore dot cc
 ID:   31324
 User updated by:  phpbug at tore dot cc
 Reported By:  phpbug at tore dot cc
-Status:   Bogus
+Status:   Open
 Bug Type: Strings related
 Operating System: Solaris 10
 PHP Version:  5.0.2
 New Comment:

Are 64bit processors not supported by php?
Which machine architecture is 'my system'?

The php is compiled with gcc2 AND gcc3. With solaris 9 AND solaris 10.
The same trouble occurs.
So I need to have the code for 'strlen' in php extracted before I can
figure out where the source for the trouble is.

A simple C-program using string.h's strlen cause no troule at all.


Previous Comments:


[2004-12-29 21:42:53] [EMAIL PROTECTED]

Sounds like either a compiler or libc bug. I cannot replicate this on
my systems either.



[2004-12-29 19:13:28] phpbug at tore dot cc

I might add that I tried php-5.0.3 on an intel-based solaris 10 machine
and there were no problems with the strlen.



[2004-12-29 07:34:41] phpbug at tore dot cc

I have used gcc2 and gcc3 to compile.
The machine is a sparc.
The problem occurs on solaris 9 and solaris 10.
If you suspect that this is a solaris problem, can you extract the code
for 'strlen' in php. I could make some tests in C



[2004-12-28 23:59:37] [EMAIL PROTECTED]

It still works fine for me on Linux. Which compiler did you use to
compile PHP (gcc or sun workshop), and what kind of platform do you
use? intel (32/64), sparc...



[2004-12-28 23:40:36] phpbug at tore dot cc

Sorry, my mistake!
It seems to work on one char long strings.
I made a better script (still avoiding loops...).

?php
$s=pack(C*,0x8e,0x8f);
$t=pack(C*,0x8e);
$u=pack(C*,0x8e,0x8f,0x90);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?


Result:
The variable s has the length: 1 
The variable t has the length: 1 
The variable u has the length: 2

The result should be:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

Since s=2 chars, t=1 char and u 3 chars long.

Lets try another test with 7 bit chars.

?php
$s=pack(C*,0x30,0x31);
$t=pack(C*,0x30);
$u=pack(C*,0x30,0x31,0x32);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?

Result:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

As expected. No problem with low values on the chars.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/31324

-- 
Edit this bug report at http://bugs.php.net/?id=31324edit=1


#31324 [NEW]: function strlen miscounts

2004-12-28 Thread phpbug at tore dot cc
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;$i256;$i++){
$s.=pack(C,$i);
$result = count_chars($s, 0);
$l=0;
for ($j=0; $j  256; $j++) {
$l+=$result[$j];
}
print brThe 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=31324edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31324r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31324r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31324r=trysnapshot51
Fixed in CVS:http://bugs.php.net/fix.php?id=31324r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=31324r=alreadyfixed
Need backtrace:  http://bugs.php.net/fix.php?id=31324r=needtrace
Need Reproduce Script:   http://bugs.php.net/fix.php?id=31324r=needscript
Try newer version:   http://bugs.php.net/fix.php?id=31324r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31324r=support
Expected behavior:   http://bugs.php.net/fix.php?id=31324r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=31324r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=31324r=submittedtwice
register_globals:http://bugs.php.net/fix.php?id=31324r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31324r=php3
Daylight Savings:http://bugs.php.net/fix.php?id=31324r=dst
IIS Stability:   http://bugs.php.net/fix.php?id=31324r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31324r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31324r=float
No Zend Extensions:  http://bugs.php.net/fix.php?id=31324r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31324r=mysqlcfg


#31324 [Opn]: function strlen miscounts

2004-12-28 Thread phpbug at tore dot cc
 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;$i256;$i++){
$s.=pack(C,$i);
$result = count_chars($s, 0);
$l=0;
for ($j=0; $j  256; $j++) {
$l+=$result[$j];
}
print brThe 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=31324edit=1


#31324 [Fbk-Opn]: function strlen miscounts

2004-12-28 Thread phpbug at tore dot cc
 ID:   31324
 User updated by:  phpbug at tore dot cc
 Reported By:  phpbug at tore dot cc
-Status:   Feedback
+Status:   Open
 Bug Type: Strings related
 Operating System: Solaris 10
 PHP Version:  5.0.2
 New Comment:

How about:
?php
$s=pack(C,143);
$result = count_chars($s, 0);
print The variable s has the length:  .
   strlen($s) .  (actual length)  . $result[143] .  
   \n;
?
Gives printout:
The variable s has the length: 0 (actual length) 1

The 'pack' creates a bit-string with a length of 1 char.
The 'strlen' should should recognize it as a char with length 1. As you
can see below 'strlen' does not only miscalculates the string length for
the char 143.


Previous Comments:


[2004-12-28 19:19:36] [EMAIL PROTECTED]

I don't understand what your script is doing, please come up with a
trivial script instead of those loops.




[2004-12-28 18:38:55] phpbug at tore dot cc

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



[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;$i256;$i++){
$s.=pack(C,$i);
$result = count_chars($s, 0);
$l=0;
for ($j=0; $j  256; $j++) {
$l+=$result[$j];
}
print brThe 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=31324edit=1


#31324 [Fbk-Opn]: function strlen miscounts

2004-12-28 Thread phpbug at tore dot cc
 ID:   31324
 User updated by:  phpbug at tore dot cc
 Reported By:  phpbug at tore dot cc
-Status:   Feedback
+Status:   Open
 Bug Type: Strings related
 Operating System: Solaris 10
 PHP Version:  5.0.2
 New Comment:

Sorry, my mistake!
It seems to work on one char long strings.
I made a better script (still avoiding loops...).

?php
$s=pack(C*,0x8e,0x8f);
$t=pack(C*,0x8e);
$u=pack(C*,0x8e,0x8f,0x90);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?


Result:
The variable s has the length: 1 
The variable t has the length: 1 
The variable u has the length: 2

The result should be:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

Since s=2 chars, t=1 char and u 3 chars long.

Lets try another test with 7 bit chars.

?php
$s=pack(C*,0x30,0x31);
$t=pack(C*,0x30);
$u=pack(C*,0x30,0x31,0x32);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?

Result:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

As expected. No problem with low values on the chars.


Previous Comments:


[2004-12-28 23:07:29] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Both in 4.3.10RC2, 5.0.3-dev, and 5.1.0-dev it prints as expected:
The variable s has the length: 1 (actual length) 1
So please try a snapshot.



[2004-12-28 21:57:50] phpbug at tore dot cc

How about:
?php
$s=pack(C,143);
$result = count_chars($s, 0);
print The variable s has the length:  .
   strlen($s) .  (actual length)  . $result[143] .  
   \n;
?
Gives printout:
The variable s has the length: 0 (actual length) 1

The 'pack' creates a bit-string with a length of 1 char.
The 'strlen' should should recognize it as a char with length 1. As you
can see below 'strlen' does not only miscalculates the string length for
the char 143.



[2004-12-28 19:19:36] [EMAIL PROTECTED]

I don't understand what your script is doing, please come up with a
trivial script instead of those loops.




[2004-12-28 18:38:55] phpbug at tore dot cc

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



[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;$i256;$i++){
$s.=pack(C,$i);
$result = count_chars($s, 0);
$l=0;
for ($j=0; $j  256; $j++) {
$l+=$result[$j];
}
print brThe 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

#31324 [Fbk-Opn]: function strlen miscounts

2004-12-28 Thread phpbug at tore dot cc
 ID:   31324
 User updated by:  phpbug at tore dot cc
 Reported By:  phpbug at tore dot cc
-Status:   Feedback
+Status:   Open
 Bug Type: Strings related
 Operating System: Solaris 10
 PHP Version:  5.0.2
 New Comment:

I have used gcc2 and gcc3 to compile.
The machine is a sparc.
The problem occurs on solaris 9 and solaris 10.
If you suspect that this is a solaris problem, can you extract the code
for 'strlen' in php. I could make some tests in C


Previous Comments:


[2004-12-28 23:59:37] [EMAIL PROTECTED]

It still works fine for me on Linux. Which compiler did you use to
compile PHP (gcc or sun workshop), and what kind of platform do you
use? intel (32/64), sparc...



[2004-12-28 23:40:36] phpbug at tore dot cc

Sorry, my mistake!
It seems to work on one char long strings.
I made a better script (still avoiding loops...).

?php
$s=pack(C*,0x8e,0x8f);
$t=pack(C*,0x8e);
$u=pack(C*,0x8e,0x8f,0x90);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?


Result:
The variable s has the length: 1 
The variable t has the length: 1 
The variable u has the length: 2

The result should be:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

Since s=2 chars, t=1 char and u 3 chars long.

Lets try another test with 7 bit chars.

?php
$s=pack(C*,0x30,0x31);
$t=pack(C*,0x30);
$u=pack(C*,0x30,0x31,0x32);
print The variable s has the length:  . strlen($s) . \n;
print The variable t has the length:  . strlen($t) . \n;
print The variable u has the length:  . strlen($u) . \n;
?

Result:
The variable s has the length: 2 
The variable t has the length: 1 
The variable u has the length: 3

As expected. No problem with low values on the chars.



[2004-12-28 23:07:29] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Both in 4.3.10RC2, 5.0.3-dev, and 5.1.0-dev it prints as expected:
The variable s has the length: 1 (actual length) 1
So please try a snapshot.



[2004-12-28 21:57:50] phpbug at tore dot cc

How about:
?php
$s=pack(C,143);
$result = count_chars($s, 0);
print The variable s has the length:  .
   strlen($s) .  (actual length)  . $result[143] .  
   \n;
?
Gives printout:
The variable s has the length: 0 (actual length) 1

The 'pack' creates a bit-string with a length of 1 char.
The 'strlen' should should recognize it as a char with length 1. As you
can see below 'strlen' does not only miscalculates the string length for
the char 143.



[2004-12-28 19:19:36] [EMAIL PROTECTED]

I don't understand what your script is doing, please come up with a
trivial script instead of those loops.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/31324

-- 
Edit this bug report at http://bugs.php.net/?id=31324edit=1