moriyoshi               Sat Feb 14 07:34:16 2009 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/mbstring/tests bug45923.phpt 

  Modified files:              
    /php-src/ext/mbstring       mbstring.c mbstring.h 
    /php-src/ext/mbstring/libmbfl/mbfl  mbfilter.c 
  Log:
  - MFH: fix Bug #45923 (mb_st[r]ripos() offset not handled correctly)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/mbstring.c?r1=1.224.2.22.2.25.2.47&r2=1.224.2.22.2.25.2.48&diff_format=u
Index: php-src/ext/mbstring/mbstring.c
diff -u php-src/ext/mbstring/mbstring.c:1.224.2.22.2.25.2.47 
php-src/ext/mbstring/mbstring.c:1.224.2.22.2.25.2.48
--- php-src/ext/mbstring/mbstring.c:1.224.2.22.2.25.2.47        Wed Feb 11 
14:26:24 2009
+++ php-src/ext/mbstring/mbstring.c     Sat Feb 14 07:34:15 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mbstring.c,v 1.224.2.22.2.25.2.47 2009/02/11 14:26:24 iliaa Exp $ */
+/* $Id: mbstring.c,v 1.224.2.22.2.25.2.48 2009/02/14 07:34:15 moriyoshi Exp $ 
*/
 
 /*
  * PHP 4 Multibyte String module "mbstring"
@@ -2237,12 +2237,12 @@
                }
        }
 
-       if (offset < 0 || (unsigned long)offset > (unsigned 
long)mbfl_strlen(&haystack)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not 
contained in string.");
+       if (offset < 0 || offset > mbfl_strlen(&haystack)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not 
contained in string");
                RETURN_FALSE;
        }
        if (needle.len == 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter.");
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter");
                RETURN_FALSE;
        }
 
@@ -2254,17 +2254,17 @@
                case 1:
                        break;
                case 2:
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Needle has 
not positive length.");
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Needle has 
not positive length");
                        break;
                case 4:
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
encoding or conversion error.");
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
encoding or conversion error");
                        break;
                case 8:
-                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Argument is 
empty.");
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Argument is 
empty");
                        break;
                default:
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
error in mb_strpos.");
-                       break;                  
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown 
error in mb_strpos");
+                       break;
                }
                RETVAL_FALSE;
        }
@@ -2351,10 +2351,13 @@
                RETURN_FALSE;
        }
 
-       if ((offset > 0 && offset > mbfl_strlen(&haystack)) ||
-               (offset < 0 && -offset > mbfl_strlen(&haystack))) {
-               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Offset is greater 
than the length of haystack string");
-               RETURN_FALSE;
+       {
+               int haystack_char_len = mbfl_strlen(&haystack);
+               if ((offset > 0 && offset > haystack_char_len) ||
+                       (offset < 0 && -offset > haystack_char_len)) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is 
greater than the length of haystack string");
+                       RETURN_FALSE;
+               }
        }
 
        n = mbfl_strpos(&haystack, &needle, offset, 1);
@@ -2411,10 +2414,6 @@
                RETURN_FALSE;
        }
 
-       if ((unsigned int)offset > haystack.len) {
-               RETURN_FALSE;
-       }
-
        n = php_mb_stripos(1, (char *)haystack.val, haystack.len, (char 
*)needle.val, needle.len, offset, from_encoding TSRMLS_CC);
 
        if (n >= 0) {
@@ -4804,7 +4803,7 @@
 
 /* {{{ MBSTRING_API int php_mb_stripos()
  */
-MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned 
int old_haystack_len, const char *old_needle, unsigned int old_needle_len, 
unsigned int offset, const char *from_encoding TSRMLS_DC)
+MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned 
int old_haystack_len, const char *old_needle, unsigned int old_needle_len, long 
offset, const char *from_encoding TSRMLS_DC)
 {
        int n;
        mbfl_string haystack, needle;
@@ -4847,9 +4846,21 @@
                        break;
                }
 
-               if (offset < 0 || offset > haystack.len) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not 
contained in string.");
-                       break;
+               {
+                       int haystack_char_len = mbfl_strlen(&haystack);
+ 
+                       if (mode) {
+                               if ((offset > 0 && offset > haystack_char_len) 
||
+                                       (offset < 0 && -offset > 
haystack_char_len)) {
+                                       php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Offset is greater than the length of haystack string");
+                                       break;
+                               }
+                       } else {
+                               if (offset < 0 || offset > haystack_char_len) {
+                                       php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Offset not contained in string");
+                                       break;
+                               }
+                       }
                }
 
                n = mbfl_strpos(&haystack, &needle, offset, mode);
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/mbstring.h?r1=1.66.2.4.2.5.2.9&r2=1.66.2.4.2.5.2.10&diff_format=u
Index: php-src/ext/mbstring/mbstring.h
diff -u php-src/ext/mbstring/mbstring.h:1.66.2.4.2.5.2.9 
php-src/ext/mbstring/mbstring.h:1.66.2.4.2.5.2.10
--- php-src/ext/mbstring/mbstring.h:1.66.2.4.2.5.2.9    Wed Dec 31 11:15:38 2008
+++ php-src/ext/mbstring/mbstring.h     Sat Feb 14 07:34:15 2009
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mbstring.h,v 1.66.2.4.2.5.2.9 2008/12/31 11:15:38 sebastian Exp $ */
+/* $Id: mbstring.h,v 1.66.2.4.2.5.2.10 2009/02/14 07:34:15 moriyoshi Exp $ */
 
 /*
  * PHP 4 Multibyte String module "mbstring" (currently only for Japanese)
@@ -157,7 +157,7 @@
 
 MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int 
*arg_length, int num, char *arg_list TSRMLS_DC);
 
-MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned 
int old_haystack_len, const char *old_needle, unsigned int old_needle_len, 
unsigned int offset, const char *from_encoding TSRMLS_DC);
+MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned 
int old_haystack_len, const char *old_needle, unsigned int old_needle_len, long 
offset, const char *from_encoding TSRMLS_DC);
 
 ZEND_BEGIN_MODULE_GLOBALS(mbstring)
        enum mbfl_no_language language;
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c?r1=1.7.2.5.2.1.2.2&r2=1.7.2.5.2.1.2.3&diff_format=u
Index: php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c
diff -u php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c:1.7.2.5.2.1.2.2 
php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c:1.7.2.5.2.1.2.3
--- php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c:1.7.2.5.2.1.2.2        Fri Feb 
 6 07:33:25 2009
+++ php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c        Sat Feb 14 07:34:15 2009
@@ -905,7 +905,7 @@
        }
 
        if (offset < 0) {
-               negative_offset = -offset-1;
+               negative_offset = -offset - pc.needle_len;
                offset = 0;
        }
 

http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/tests/bug45923.phpt?view=markup&rev=1.1
Index: php-src/ext/mbstring/tests/bug45923.phpt
+++ php-src/ext/mbstring/tests/bug45923.phpt
--TEST--
Bug #45923 (mb_st[r]ripos() offset not handled correctly)
--SKIPIF--
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
--INI--
mbstring.internal_encoding=UTF-8
--FILE--
<?php
var_dump(strpos("abc abc abc", "abc", 0));
var_dump(strpos("abc abc abc", "abc", 3));
var_dump(strpos("abc abc abc", "abc", 6));
var_dump(strpos("abc abc abc", "abc", 9));
var_dump(strpos("abc abc abc", "abc", 11));
var_dump(strpos("abc abc abc", "abc", 12));
var_dump(strpos("abc abc abc", "abc", -1));
var_dump(strpos("abc abc abc", "abc", -3));
var_dump(strpos("abc abc abc", "abc", -6));

var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", 0));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", 3));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", 6));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", 9));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", 11));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", 12));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", -1));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", -3));
var_dump(mb_strpos("●○◆ ●○◆ ●○◆", "●○◆", -6));

var_dump(stripos("abc abc abc", "abc", 0));
var_dump(stripos("abc abc abc", "abc", 3));
var_dump(stripos("abc abc abc", "abc", 6));
var_dump(stripos("abc abc abc", "abc", 9));
var_dump(stripos("abc abc abc", "abc", 11));
var_dump(stripos("abc abc abc", "abc", 12));
var_dump(stripos("abc abc abc", "abc", -1));
var_dump(stripos("abc abc abc", "abc", -3));
var_dump(stripos("abc abc abc", "abc", -6));

var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", 0));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", 3));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", 6));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", 9));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", 11));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", 12));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", -1));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", -3));
var_dump(mb_stripos("●○◆ ●○◆ ●○◆", "●○◆", -6));

var_dump(strrpos("abc abc abc", "abc", 0));
var_dump(strrpos("abc abc abc", "abc", 3));
var_dump(strrpos("abc abc abc", "abc", 6));
var_dump(strrpos("abc abc abc", "abc", 9));
var_dump(strrpos("abc abc abc", "abc", 11));
var_dump(strrpos("abc abc abc", "abc", 12));
var_dump(strrpos("abc abc abc", "abc", -1));
var_dump(strrpos("abc abc abc", "abc", -3));
var_dump(strrpos("abc abc abc", "abc", -6));

var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", 0));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", 3));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", 6));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", 9));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", 11));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", 12));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", -1));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", -3));
var_dump(mb_strrpos("●○◆ ●○◆ ●○◆", "●○◆", -6));

var_dump(strripos("abc abc abc", "abc", 0));
var_dump(strripos("abc abc abc", "abc", 3));
var_dump(strripos("abc abc abc", "abc", 6));
var_dump(strripos("abc abc abc", "abc", 9));
var_dump(strripos("abc abc abc", "abc", 11));
var_dump(strripos("abc abc abc", "abc", 12));
var_dump(strripos("abc abc abc", "abc", -1));
var_dump(strripos("abc abc abc", "abc", -3));
var_dump(strripos("abc abc abc", "abc", -6));

var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", 0));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", 3));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", 6));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", 9));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", 11));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", 12));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", -1));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", -3));
var_dump(mb_strripos("●○◆ ●○◆ ●○◆", "●○◆", -6));

?>
--EXPECTF--
int(0)
int(4)
int(8)
bool(false)
bool(false)

Warning: strpos(): Offset not contained in string in %s on line %d
bool(false)

Warning: strpos(): Offset not contained in string in %s on line %d
bool(false)

Warning: strpos(): Offset not contained in string in %s on line %d
bool(false)

Warning: strpos(): Offset not contained in string in %s on line %d
bool(false)
int(0)
int(4)
int(8)
bool(false)
bool(false)

Warning: mb_strpos(): Offset not contained in string in %s on line %d
bool(false)

Warning: mb_strpos(): Offset not contained in string in %s on line %d
bool(false)

Warning: mb_strpos(): Offset not contained in string in %s on line %d
bool(false)

Warning: mb_strpos(): Offset not contained in string in %s on line %d
bool(false)
int(0)
int(4)
int(8)
bool(false)
bool(false)

Warning: stripos(): Offset not contained in string in %s on line %d
bool(false)

Warning: stripos(): Offset not contained in string in %s on line %d
bool(false)

Warning: stripos(): Offset not contained in string in %s on line %d
bool(false)

Warning: stripos(): Offset not contained in string in %s on line %d
bool(false)
int(0)
int(4)
int(8)
bool(false)
bool(false)

Warning: mb_stripos(): Offset not contained in string in %s on line %d
bool(false)

Warning: mb_stripos(): Offset not contained in string in %s on line %d
bool(false)

Warning: mb_stripos(): Offset not contained in string in %s on line %d
bool(false)

Warning: mb_stripos(): Offset not contained in string in %s on line %d
bool(false)
int(8)
int(8)
int(8)
bool(false)
bool(false)

Warning: strrpos(): Offset is greater than the length of haystack string in %s 
on line %d
bool(false)
int(8)
int(8)
int(4)
int(8)
int(8)
int(8)
bool(false)
bool(false)

Warning: mb_strrpos(): Offset is greater than the length of haystack string in 
%s on line %d
bool(false)
int(8)
int(8)
int(4)
int(8)
int(8)
int(8)
bool(false)
bool(false)

Warning: strripos(): Offset is greater than the length of haystack string in %s 
on line %d
bool(false)
int(8)
int(8)
int(4)
int(8)
int(8)
int(8)
bool(false)
bool(false)

Warning: mb_strripos(): Offset is greater than the length of haystack string in 
%s on line %d
bool(false)
int(8)
int(8)
int(4)

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

Reply via email to