php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49354 mb_strcut() cutting wrong length when offset is within a multibyte character
Submitted: 2009-08-25 07:33 UTC Modified: 2009-09-23 15:23 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: mk at zigamorph dot se Assigned: moriyoshi (profile)
Status: Closed Package: mbstring related
PHP Version: 5.2.10 OS: Linux
Private report: No CVE-ID: None
 [2009-08-25 07:33 UTC] mk at zigamorph dot se
Description:
------------
When you use mb_strcut with an offset and this offset happens to fall within a multibyte (utf-8) character mb_strcut moves the start point of the string as to not break a multibyte character. As an undesirable side effect it strips one or more bytes from the end of the cut string.

Reproduce code:
---------------
$crap = 'AåBäCöDü' /* in utf-8 */
echo mb_strcut($crap, 0, 100, 'UTF-8')."\n"; /* 'AåBäCöDü' as 100 is more than strlen */
echo mb_strcut($crap, 1, 100, 'UTF-8')."\n"; /* 'åBäCöDü' as 100 is more than strlen and we're offset 1 byte */
echo mb_strcut($crap, 2, 100, 'UTF-8')."\n"; /* 'åBäCöD' */

Expected result:
----------------
$crap = 'AåBäCöDü' /* in utf-8 */
echo mb_strcut($crap, 0, 100, 'UTF-8')."\n"; /* 'AåBäCöDü' as 100 is more than strlen */
echo mb_strcut($crap, 1, 100, 'UTF-8')."\n"; /* 'åBäCöDü' as 100 is more than strlen and we're offset 1 byte */
echo mb_strcut($crap, 2, 100, 'UTF-8')."\n"; /* either 'åBäCöDü' or 'BäCöDü' */


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-23 15:22 UTC] svn@php.net
Automatic comment from SVN on behalf of moriyoshi
Revision: http://svn.php.net/viewvc/?view=revision&revision=288613
Log: - Fixed bug #49354 (mb_strcut() cuts wrong length when offset is within a
  multibyte character).

(This bug was introduced by the commit by r202895. Please double-check the
 specification of the function you are going to *fix*.)
 [2009-09-23 15:23 UTC] moriyoshi@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC