cataphract                               Sat, 09 Apr 2011 16:59:36 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=310108

Log:
- Fixed bug #54494: mb_substr() mishandles UTF-32LE and UCS-2LE.

Bug: http://bugs.php.net/54494 (Open) mb_substr() fails on "UTF-32LE"
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c
    A   php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug54494.phpt
    U   php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c
    A   php/php-src/trunk/ext/mbstring/tests/bug54494.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2011-04-09 16:02:40 UTC (rev 310107)
+++ php/php-src/branches/PHP_5_3/NEWS   2011-04-09 16:59:36 UTC (rev 310108)
@@ -41,6 +41,9 @@
   . Fixed bug #53339 (Fails to build when compilng with gcc 4.5 and DSO
     libraries). (Clint Byrum, Raphael)

+- mbstring extension:
+  . Fixed bug #54494 (mb_substr() mishandles UTF-32LE and UCS-2LE). (Gustavo)
+
 - MySQL Improved extension:
   . Fixed Bug #54221 (mysqli::get_warnings segfault when used in multi 
queries).
     (Andrey)

Modified: php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c   
2011-04-09 16:02:40 UTC (rev 310107)
+++ php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c   
2011-04-09 16:59:36 UTC (rev 310108)
@@ -1202,10 +1202,10 @@
                len = string->len;
                start = from;
                end = from + length;
-               if (encoding->flag & (MBFL_ENCTYPE_WCS2BE | 
MBFL_ENCTYPE_MWC2LE)) {
+               if (encoding->flag & (MBFL_ENCTYPE_WCS2BE | 
MBFL_ENCTYPE_WCS2LE)) {
                        start *= 2;
                        end = start + length*2;
-               } else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | 
MBFL_ENCTYPE_MWC4LE)) {
+               } else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | 
MBFL_ENCTYPE_WCS4LE)) {
                        start *= 4;
                        end = start + length*4;
                } else if (encoding->mblen_table != NULL) {

Added: php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug54494.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug54494.phpt               
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug54494.phpt       
2011-04-09 16:59:36 UTC (rev 310108)
@@ -0,0 +1,52 @@
+--TEST--
+Bug #54494: mb_substr() mishandles UTF-32LE and UCS-2LE
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+
+//declare(encoding = 'UTF-8');
+mb_internal_encoding('UTF-8');
+
+header('Content-Type: text/plain; charset=UTF-32LE');
+
+$stringOr = "hällö wörld\n";
+
+$mode = "UTF-32LE";
+
+echo "$mode:\n";
+
+$string = mb_convert_encoding($stringOr, $mode);
+$length = mb_strlen($string, $mode);
+echo "Length: ", $length, "\n";
+
+
+for ($i=0; $i < $length; $i++) {
+  $t = unpack("H*",mb_substr($string, $i, 1, $mode));
+  echo $t[1];
+}
+echo "\n";
+
+
+$mode = "UCS-2LE";
+
+echo "$mode:\n";
+
+$string = mb_convert_encoding($stringOr, $mode);
+$length = mb_strlen($string, $mode);
+echo "Length: ", $length, "\n";
+
+
+for ($i=0; $i < $length; $i++) {
+  $t = unpack("H*",mb_substr($string, $i, 1, $mode));
+  echo $t[1];
+}
+echo "\n";
+--EXPECT--
+UTF-32LE:
+Length: 12
+68000000e40000006c0000006c000000f60000002000000077000000f6000000720000006c000000640000000a000000
+UCS-2LE:
+Length: 12
+6800e4006c006c00f60020007700f60072006c0064000a00
+

Modified: php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c
===================================================================
--- php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c      2011-04-09 
16:02:40 UTC (rev 310107)
+++ php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c      2011-04-09 
16:59:36 UTC (rev 310108)
@@ -1322,10 +1322,10 @@
                len = string->len;
                start = from;
                end = from + length;
-               if (encoding->flag & (MBFL_ENCTYPE_WCS2BE | 
MBFL_ENCTYPE_MWC2LE)) {
+               if (encoding->flag & (MBFL_ENCTYPE_WCS2BE | 
MBFL_ENCTYPE_WCS2LE)) {
                        start *= 2;
                        end = start + length*2;
-               } else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | 
MBFL_ENCTYPE_MWC4LE)) {
+               } else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | 
MBFL_ENCTYPE_WCS4LE)) {
                        start *= 4;
                        end = start + length*4;
                } else if (encoding->mblen_table != NULL) {

Added: php/php-src/trunk/ext/mbstring/tests/bug54494.phpt
===================================================================
--- php/php-src/trunk/ext/mbstring/tests/bug54494.phpt                          
(rev 0)
+++ php/php-src/trunk/ext/mbstring/tests/bug54494.phpt  2011-04-09 16:59:36 UTC 
(rev 310108)
@@ -0,0 +1,52 @@
+--TEST--
+Bug #54494: mb_substr() mishandles UTF-32LE and UCS-2LE
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+
+//declare(encoding = 'UTF-8');
+mb_internal_encoding('UTF-8');
+
+header('Content-Type: text/plain; charset=UTF-32LE');
+
+$stringOr = "hällö wörld\n";
+
+$mode = "UTF-32LE";
+
+echo "$mode:\n";
+
+$string = mb_convert_encoding($stringOr, $mode);
+$length = mb_strlen($string, $mode);
+echo "Length: ", $length, "\n";
+
+
+for ($i=0; $i < $length; $i++) {
+  $t = unpack("H*",mb_substr($string, $i, 1, $mode));
+  echo $t[1];
+}
+echo "\n";
+
+
+$mode = "UCS-2LE";
+
+echo "$mode:\n";
+
+$string = mb_convert_encoding($stringOr, $mode);
+$length = mb_strlen($string, $mode);
+echo "Length: ", $length, "\n";
+
+
+for ($i=0; $i < $length; $i++) {
+  $t = unpack("H*",mb_substr($string, $i, 1, $mode));
+  echo $t[1];
+}
+echo "\n";
+--EXPECT--
+UTF-32LE:
+Length: 12
+68000000e40000006c0000006c000000f60000002000000077000000f6000000720000006c000000640000000a000000
+UCS-2LE:
+Length: 12
+6800e4006c006c00f60020007700f60072006c0064000a00
+

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to