Skip to content

Commit 8c92442

Browse files
committed
Fixed bug #76747 (Opcache treats path containing "test.pharma.tld" as a phar file)
1 parent e20baee commit 8c92442

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP NEWS
1919
. Fixed bug #76704 (mb_detect_order return value varies based on argument
2020
type). (cmb)
2121

22+
- Opcache:
23+
. Fixed bug #76747 (Opcache treats path containing "test.pharma.tld" as a phar
24+
file). (Laruence)
25+
2226
- phpdbg:
2327
. Fixed bug #76595 (phpdbg man page contains outdated information).
2428
(Kevin Abel)

ext/opcache/ZendAccelerator.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,13 @@ static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_ha
12161216
}
12171217
}
12181218

1219+
static zend_always_inline zend_bool is_phar_file(zend_string *filename)
1220+
{
1221+
return filename && ZSTR_LEN(filename) >= sizeof(".phar") &&
1222+
!memcmp(ZSTR_VAL(filename) + ZSTR_LEN(filename) - (sizeof(".phar")-1), ".phar", sizeof(".phar")-1) &&
1223+
!strstr(ZSTR_VAL(filename), "://");
1224+
}
1225+
12191226
#ifdef HAVE_OPCACHE_FILE_CACHE
12201227
static zend_persistent_script *store_script_in_file_cache(zend_persistent_script *new_persistent_script)
12211228
{
@@ -1240,10 +1247,7 @@ static zend_persistent_script *store_script_in_file_cache(zend_persistent_script
12401247

12411248
zend_shared_alloc_destroy_xlat_table();
12421249

1243-
new_persistent_script->is_phar =
1244-
new_persistent_script->script.filename &&
1245-
strstr(ZSTR_VAL(new_persistent_script->script.filename), ".phar") &&
1246-
!strstr(ZSTR_VAL(new_persistent_script->script.filename), "://");
1250+
new_persistent_script->is_phar = is_phar_file(new_persistent_script->script.filename);
12471251

12481252
/* Consistency check */
12491253
if ((char*)new_persistent_script->mem + new_persistent_script->size != (char*)ZCG(mem)) {
@@ -1359,10 +1363,7 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
13591363

13601364
zend_shared_alloc_destroy_xlat_table();
13611365

1362-
new_persistent_script->is_phar =
1363-
new_persistent_script->script.filename &&
1364-
strstr(ZSTR_VAL(new_persistent_script->script.filename), ".phar") &&
1365-
!strstr(ZSTR_VAL(new_persistent_script->script.filename), "://");
1366+
new_persistent_script->is_phar = is_phar_file(new_persistent_script->script.filename);
13661367

13671368
/* Consistency check */
13681369
if ((char*)new_persistent_script->mem + new_persistent_script->size != (char*)ZCG(mem)) {

0 commit comments

Comments
 (0)