Skip to content

Commit 20771e2

Browse files
committed
Flag already interned strings utf8-valid
1 parent 83f9d5c commit 20771e2

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎ext/mbstring/mbstring.c‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,9 @@ static zend_string* mb_get_substr(zend_string *input, size_t from, size_t len, c
22462246
}
22472247
}
22482248
zend_string *result = zend_string_init_fast((const char*)start, stop - start);
2249-
if (!ZSTR_IS_INTERNED(result)) {
2249+
if (ZSTR_IS_INTERNED(result)) {
2250+
GC_ADD_FLAGS_ATOMIC(result, IS_STR_VALID_UTF8);
2251+
} else {
22502252
GC_ADD_FLAGS(result, IS_STR_VALID_UTF8);
22512253
}
22522254
return result;
@@ -2364,8 +2366,12 @@ PHP_FUNCTION(mb_substr_count)
23642366
} else {
23652367
unsigned int num_errors = 0;
23662368
haystack_u8 = mb_fast_convert((unsigned char*)ZSTR_VAL(haystack), ZSTR_LEN(haystack), enc, &mbfl_encoding_utf8, 0, MBFL_OUTPUTFILTER_ILLEGAL_MODE_BADUTF8, &num_errors);
2367-
if (!num_errors && !ZSTR_IS_INTERNED(haystack)) {
2368-
GC_ADD_FLAGS(haystack, IS_STR_VALID_UTF8);
2369+
if (!num_errors) {
2370+
if (ZSTR_IS_INTERNED(haystack)) {
2371+
GC_ADD_FLAGS_ATOMIC(haystack, IS_STR_VALID_UTF8);
2372+
} else {
2373+
GC_ADD_FLAGS(haystack, IS_STR_VALID_UTF8);
2374+
}
23692375
}
23702376
}
23712377

@@ -2374,8 +2380,12 @@ PHP_FUNCTION(mb_substr_count)
23742380
} else {
23752381
unsigned int num_errors = 0;
23762382
needle_u8 = mb_fast_convert((unsigned char*)ZSTR_VAL(needle), ZSTR_LEN(needle), enc, &mbfl_encoding_utf8, 0, MBFL_OUTPUTFILTER_ILLEGAL_MODE_BADUTF8, &num_errors);
2377-
if (!num_errors && !ZSTR_IS_INTERNED(needle)) {
2378-
GC_ADD_FLAGS(needle, IS_STR_VALID_UTF8);
2383+
if (!num_errors) {
2384+
if (ZSTR_IS_INTERNED(needle)) {
2385+
GC_ADD_FLAGS_ATOMIC(needle, IS_STR_VALID_UTF8);
2386+
} else {
2387+
GC_ADD_FLAGS(needle, IS_STR_VALID_UTF8);
2388+
}
23792389
}
23802390
}
23812391
} else {
@@ -5756,8 +5766,12 @@ static bool mb_check_str_encoding(zend_string *str, const mbfl_encoding *encodin
57565766
return true;
57575767
}
57585768
bool result = mb_fast_check_utf8(str);
5759-
if (result && !ZSTR_IS_INTERNED(str)) {
5760-
GC_ADD_FLAGS(str, IS_STR_VALID_UTF8);
5769+
if (result) {
5770+
if (ZSTR_IS_INTERNED(str)) {
5771+
GC_ADD_FLAGS_ATOMIC(str, IS_STR_VALID_UTF8);
5772+
} else if(!ZSTR_IS_INTERNED(str)) {
5773+
GC_ADD_FLAGS(str, IS_STR_VALID_UTF8);
5774+
}
57615775
}
57625776
return result;
57635777
} else {

‎ext/pcre/php_pcre.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,9 +1508,12 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
15081508

15091509
if (PCRE_G(error_code) == PHP_PCRE_NO_ERROR) {
15101510
/* If there was no error and we're in /u mode, remember that the string is valid UTF-8. */
1511-
if ((pce->compile_options & PCRE2_UTF)
1512-
&& !ZSTR_IS_INTERNED(subject_str) && orig_start_offset == 0) {
1513-
GC_ADD_FLAGS(subject_str, IS_STR_VALID_UTF8);
1511+
if ((pce->compile_options & PCRE2_UTF) && orig_start_offset == 0) {
1512+
if (ZSTR_IS_INTERNED(subject_str)) {
1513+
GC_ADD_FLAGS_ATOMIC(subject_str, IS_STR_VALID_UTF8);
1514+
} else {
1515+
GC_ADD_FLAGS(subject_str, IS_STR_VALID_UTF8);
1516+
}
15141517
}
15151518

15161519
RETVAL_LONG(matched);

0 commit comments

Comments
 (0)