Skip to content

Commit bba4a8a

Browse files
committed
Fixed bug #68644 (strlen incorrect : mbstring + func_overload=2 +UTF-8 + Opcache)
1 parent 87ccf50 commit bba4a8a

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ PHP NEWS
3838
(Ashesh Vashi)
3939

4040
- Opcache:
41+
. Fixed bug #68644 (strlen incorrect : mbstring + func_overload=2 +UTF-8
42+
+ Opcache). (Laruence)
4143
. Fixed bug #67111 (Memory leak when using "continue 2" inside two foreach
4244
loops). (Nikita)
4345

ext/opcache/Optimizer/pass1_5.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,11 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
450450
MAKE_NOP(opline);
451451
}
452452
}
453-
} else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("strlen")-1 &&
454-
!memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
455-
"strlen", sizeof("strlen")-1)) {
453+
} else if ((!zend_hash_exists(&module_registry, "mbstring", sizeof("mbstring")) ||
454+
zend_ini_long("mbstring.func_overload",
455+
sizeof("mbstring.func_overload"), 0) < 2 /* MB_OVERLOAD_STRING */) &&
456+
Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("strlen") - 1 &&
457+
!memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), "strlen", sizeof("strlen") - 1)) {
456458
zval t;
457459

458460
ZVAL_LONG(&t, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));

ext/opcache/tests/bug68644.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #68644 strlen incorrect : mbstring + func_overload=2 + UTF-8 + Opcache
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
mbstring.func_overload=2
7+
mbstring.internal_encoding=UTF-8
8+
--SKIPIF--
9+
<?php if (!extension_loaded('Zend OPcache') || !extension_loaded("mbstring")) die("skip"); ?>
10+
--FILE--
11+
<?php
12+
var_dump(strlen("中国, 北京"));
13+
var_dump(mb_strlen("中国, 北京"));
14+
?>
15+
--EXPECT--
16+
int(6)
17+
int(6)

0 commit comments

Comments
 (0)