mirror of
https://github.com/php/php-src.git
synced 2024-11-24 10:24:11 +08:00
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #74170: locale information change after mime_content_type
This commit is contained in:
commit
d4ba1fd963
@ -527,11 +527,9 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
|
||||
zend_string *repl;
|
||||
size_t rep_cnt = 0;
|
||||
|
||||
(void)setlocale(LC_CTYPE, "C");
|
||||
|
||||
opts |= PCRE2_MULTILINE;
|
||||
convert_libmagic_pattern(&patt, (char*)pat, strlen(pat), opts);
|
||||
if ((pce = pcre_get_compiled_regex_cache(Z_STR(patt))) == NULL) {
|
||||
if ((pce = pcre_get_compiled_regex_cache_ex(Z_STR(patt), 0)) == NULL) {
|
||||
zval_ptr_dtor(&patt);
|
||||
rep_cnt = -1;
|
||||
goto out;
|
||||
@ -553,7 +551,6 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
|
||||
zend_string_release_ex(res, 0);
|
||||
|
||||
out:
|
||||
(void)setlocale(LC_CTYPE, "");
|
||||
return rep_cnt;
|
||||
}
|
||||
|
||||
|
@ -112,14 +112,24 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
|
||||
{
|
||||
size_t i;
|
||||
const char *rv = NULL;
|
||||
char *vbuf_lower;
|
||||
|
||||
(void)setlocale(LC_CTYPE, "C");
|
||||
for (i = 0; nv[i].pattern != NULL; i++)
|
||||
if (strcasestr(vbuf, nv[i].pattern) != NULL) {
|
||||
vbuf_lower = zend_str_tolower_dup(vbuf, strlen(vbuf));
|
||||
for (i = 0; nv[i].pattern != NULL; i++) {
|
||||
char *pattern_lower;
|
||||
int found;
|
||||
|
||||
pattern_lower = zend_str_tolower_dup(nv[i].pattern, strlen(nv[i].pattern));
|
||||
found = (strstr(vbuf_lower, pattern_lower) != NULL);
|
||||
efree(pattern_lower);
|
||||
|
||||
if (found) {
|
||||
rv = nv[i].mime;
|
||||
break;
|
||||
}
|
||||
(void)setlocale(LC_CTYPE, "");
|
||||
}
|
||||
|
||||
efree(vbuf_lower);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -469,27 +469,25 @@ flush:
|
||||
private int
|
||||
check_fmt(struct magic_set *ms, const char *fmt)
|
||||
{
|
||||
pcre2_code *pce;
|
||||
uint32_t capture_count;
|
||||
pcre_cache_entry *pce;
|
||||
int rv = -1;
|
||||
zend_string *pattern;
|
||||
|
||||
if (strchr(fmt, '%') == NULL)
|
||||
return 0;
|
||||
|
||||
(void)setlocale(LC_CTYPE, "C");
|
||||
pattern = zend_string_init("~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, 0);
|
||||
if ((pce = pcre_get_compiled_regex(pattern, &capture_count)) == NULL) {
|
||||
if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0)) == NULL) {
|
||||
rv = -1;
|
||||
} else {
|
||||
pcre2_match_data *match_data = php_pcre_create_match_data(capture_count, pce);
|
||||
pcre2_code *re = php_pcre_pce_re(pce);
|
||||
pcre2_match_data *match_data = php_pcre_create_match_data(0, re);
|
||||
if (match_data) {
|
||||
rv = pcre2_match(pce, (PCRE2_SPTR)fmt, strlen(fmt), 0, 0, match_data, php_pcre_mctx()) > 0;
|
||||
rv = pcre2_match(re, (PCRE2_SPTR)fmt, strlen(fmt), 0, 0, match_data, php_pcre_mctx()) > 0;
|
||||
php_pcre_free_match_data(match_data);
|
||||
}
|
||||
}
|
||||
zend_string_release_ex(pattern, 0);
|
||||
(void)setlocale(LC_CTYPE, "");
|
||||
zend_string_release(pattern);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
22
ext/fileinfo/tests/bug74170.phpt
Normal file
22
ext/fileinfo/tests/bug74170.phpt
Normal file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
Bug #74170 locale information change after mime_content_type
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!class_exists('finfo'))
|
||||
die('skip no fileinfo extension');
|
||||
if (!extension_loaded('intl'))
|
||||
die('skip intl extension not enabled');
|
||||
if (setlocale(LC_CTYPE, 'ru_RU.koi8r') === false)
|
||||
die('skip ru_RU.koi8r locale is not available');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(setlocale(LC_CTYPE, 'ru_RU.koi8r'));
|
||||
var_dump(nl_langinfo(CODESET));
|
||||
var_dump(mime_content_type(__DIR__ . '/resources/test.ppt'));
|
||||
var_dump(nl_langinfo(CODESET));
|
||||
--EXPECT--
|
||||
string(11) "ru_RU.koi8r"
|
||||
string(6) "KOI8-R"
|
||||
string(29) "application/vnd.ms-powerpoint"
|
||||
string(6) "KOI8-R"
|
Loading…
Reference in New Issue
Block a user