In lots of places we are making the assumption that strlen() will always return the size in bytes of a variable/string.
And that works in 99% of sites.
But it's possible to have that default behavior altered with mbstring.func_overload, leading to unpredictable results here and there (really hard to reproduce, debug).
So this is a proposal about to consider adding a function/method, let's call it strbytes() for now (more below), basically doing:
function strbytes($string) {
|
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
return mb_strlen($string, '8bit');
|
} else {
|
return strlen($string);
|
}
|
}
|
And start applying it to all the places where we are, blindly, using strlen() to calculate in bytes. This basic/incomplete grep reveals a number of them grep -r size.*strlen *
I can imagine it implemented as:
1) a new parameter to existing core_text::strlen() function
2) a brand new core_text::strbytes() function.
My vote goes to 2).
Ciao
- has been marked as being related by
-
MDL-55028 SOAP WSDL request sends header "Content-Length: 1"
-
- Closed
-
-
MDL-53709 Return the content size in mod_wiki_get_subwiki_pages if includecontent=0
-
- Closed
-
- will help resolve
-
MDL-56109 For some binary files add_string_to_pool wrongly evaluates filesize when strlen() is overloaded (mbstring.func_overload)
-
- Closed
-