php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47148 strlen return wrong character number with one chars sequense
Submitted: 2009-01-19 11:38 UTC Modified: 2009-01-19 13:51 UTC
From: llongo at sata-hts dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.8 OS: Linux CentOS 5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: llongo at sata-hts dot com
New email:
PHP Version: OS:

 

 [2009-01-19 11:38 UTC] llongo at sata-hts dot com
Description:
------------
Passing to strlen a string with a particular sequence of characters (binary + ascii), strlen returns the wrong number of characters.

The architecture of the host where the problem has happened is x86_64

The php configure is:
./configure --with-openssl --with-zlib --enable-zip --with-pear --with-
mysql --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-shmop --enable-pcntl --enable-bcmath --with-apxs
2 --with-gettext --with-gdbm --enable-sockets --enable-mbstring --with-imap-ssl --with-libdir=lib64

Reproduce code:
---------------
$pack_str = pack("N",240); // binary string
$msg = "<msg>"; // ascii string
echo "pack_str: ".strlen($pack_str)."\n"; // OK
echo "msg: ".strlen($msg)."\n"; // OK
$new_str = $pack_str.$msg;
echo "strlen: ".strlen($new_str)."\n"; // KO

Expected result:
----------------
The expected result of last echo is:
strlen: 9

Actual result:
--------------
The actual result of last echo is:
strlen: 6

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-19 12:38 UTC] jani@php.net
I can not reproduce this:

[jani@bfit ~]$ php t.pho 
pack_str: 4
msg: 5
strlen: 9
[jani@bfit ~]$ php -v
PHP 5.2.8 (cli) (built: Jan  8 2009 02:31:38) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
[jani@bfit ~]$ uname -a
Linux bfit 2.6.18-92.1.22.el5.centos.plus #1 SMP Wed Dec 17 10:49:19 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
[jani@bfit ~]$ 

 [2009-01-19 13:14 UTC] llongo at sata-hts dot com
Now I've read the documentation about strlen and mb_strlen and the overloading of strlen. I think my problem is caused by default encoding. I've soved using mb_strlen($str,"ASCII"), this is not a bug. Thanks for your attention.
 [2009-01-19 13:51 UTC] jani@php.net
Yes, mbstring overload stuff is bad idea usually..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 09 20:01:31 2024 UTC