Skip to content

Commit 6f18d7e

Browse files
committed
Fix #77932: File extensions are case-sensitive
The file extension to mime type mapping *must* not depend on the file extension's case for case-insensitive file systems, and *should* not for case-sensitive file systems.
1 parent 874284d commit 6f18d7e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug #79884 (PHP_CONFIG_FILE_PATH is meaningless). (cmb)
7+
. Fixed bug #77932 (File extensions are case-sensitive). (cmb)
78

89
?? ??? ????, PHP 7.3.21
910

sapi/cli/php_cli_server.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,13 @@ static void append_essential_headers(smart_str* buffer, php_cli_server_client *c
365365

366366
static const char *get_mime_type(const php_cli_server *server, const char *ext, size_t ext_len) /* {{{ */
367367
{
368-
return (const char*)zend_hash_str_find_ptr(&server->extension_mime_types, ext, ext_len);
368+
char *ret;
369+
ALLOCA_FLAG(use_heap)
370+
char *ext_lower = do_alloca(ext_len + 1, use_heap);
371+
zend_str_tolower_copy(ext_lower, ext, ext_len);
372+
ret = zend_hash_str_find_ptr(&server->extension_mime_types, ext_lower, ext_len);
373+
free_alloca(ext_lower, use_heap);
374+
return (const char*)ret;
369375
} /* }}} */
370376

371377
PHP_FUNCTION(apache_request_headers) /* {{{ */
@@ -2140,9 +2146,12 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
21402146
static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client *client) /* {{{ */
21412147
{
21422148
int is_static_file = 0;
2149+
const char *ext = client->request.ext;
21432150

21442151
SG(server_context) = client;
2145-
if (client->request.ext_len != 3 || memcmp(client->request.ext, "php", 3) || !client->request.path_translated) {
2152+
if (client->request.ext_len != 3
2153+
|| (ext[0] != 'p' && ext[0] != 'P') || (ext[1] != 'h' && ext[1] != 'H') || (ext[2] != 'p' && ext[2] != 'P')
2154+
|| !client->request.path_translated) {
21462155
is_static_file = 1;
21472156
}
21482157

0 commit comments

Comments
 (0)