-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix #74170: locale information change after mime_content_type #4645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Looks like this is not upstream code, but something we're patching in ourselves: php-src/ext/fileinfo/libmagic.patch Lines 2414 to 2448 in 06c257e
This looks pretty bogus to me. pcre_get_compiled_regex_cache() uses BG(locale_string), not the actual locale that setlocale sets, so I suspect that the current setlocale call doesn't actually do anything at all as far as PCRE is concerned. I think the correct way to fix this would be to extend the pcre_get_compiled_regex_cache API to accept the locale string as a parameter, so we can just directly pass the |
I could do that, if you don't mind? But! There is another place where setlocale is used and it is not related to PCRE. php-src/ext/fileinfo/libmagic/readcdf.c Lines 118 to 132 in 08d8623
That still needs fixing. (We could theoretically use Intl extension but that will create unnecessary dependency and it will complicate code as whole). What is your decision on that account? |
Feel free :) I would suggest not changing pcre_get_compiled_regex_cache() itself, but adding a new function like pcre_get_compiled_regex_cache_with_locale() and making the old function call it with BG(locale_string).
Though backing up the old locale would be an improvement, locale changes are still fundamentally not thread-safe, so it would be best to avoid it. We don't seem to have a ready-made function for strcasestr in particular, but an easy way to emulate it is to call |
|
@turchanov can we get a status update here please ? |
|
Sorry for late reply. Will look into that ASAP. |
Some functions in libmagic (distributed with fileinfo extension) perform this sequence of calls:
func() {
setlocale(LC_TYPE, "C")
.. do some work ..
setlocale(LC_TYPE, "")
}
It effectively resets LC_TYPE if it that was set before the function call.
To avoid manipulations with current locale at all, the problematic functions
were modified to use locale-independent functions.
|
I originally created pull request against master branch by accident. So I rebased my PR against PHP-7.2 branch. Plus I decided to squash first commit (where I save current locale before setlocale("C")) since it is no longer relevant to the current solution and will clutter the commits history. |
|
Belatedly noticed two cosmetic flaws. Pushed another commit. I can squash again to one commit if needed. |
|
So.... What do you think? |
nikic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, this looks good!
|
So... Will you merge it? |
|
Whoops, this dropped off my radar, again. Now merged as c62cd9a. |
Fix for bug #74170.
Some functions in libmagic (distributed with fileinfo extension) perform this sequence of calls:
func() {
setlocale(LC_TYPE, "C")
.. do some work ..
setlocale(LC_TYPE, "")
}
It effectively resets LC_TYPE if it that was set before the function call.
This bug was fixed in upstream file[aka libmagic] ver 5.18
(file/file@c397fb2)
So I just humbly ported it.