Skip to content

Commit 0988554

Browse files
committed
Fixed issue #115 (path issue when using phar).
1 parent cb47396 commit 0988554

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ PHP NEWS
5151
imap). (ryotakatsuki at gmail dot com)
5252

5353
- OPcache:
54+
. Fixed issue #115 (path issue when using phar). (Laruence)
5455
. Added support for GNU Hurd. (Svante Signell)
5556
. Added function opcache_compile_file() to load PHP scripts into cache
5657
without execution. (Julien)

ext/opcache/ZendAccelerator.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "zend_API.h"
3838
#include "zend_ini.h"
3939
#include "TSRM/tsrm_virtual_cwd.h"
40+
#include "ext/phar/php_phar.h"
4041
#include "zend_accelerator_util_funcs.h"
4142
#include "zend_accelerator_hash.h"
4243

@@ -144,6 +145,21 @@ static inline int is_cacheable_stream_path(const char *filename)
144145
memcmp(filename, "phar://", sizeof("phar://") - 1) == 0;
145146
}
146147

148+
static inline int is_phar_relative_alias_path(const char *filename, char **alias, int *alias_len)
149+
{
150+
if (memcmp(filename, "phar://", sizeof("phar://") - 1) == 0
151+
&& filename[sizeof("phar://") - 1] != '\0' && filename[sizeof("phar://") - 1] != '/') {
152+
char *slash;
153+
*alias = filename + sizeof("phar://") - 1;
154+
slash = strstr(*alias, "/");
155+
if (slash) {
156+
*alias_len = slash - *alias;
157+
return 1;
158+
}
159+
}
160+
return 0;
161+
}
162+
147163
/* O+ overrides PHP chdir() function and remembers the current working directory
148164
* in ZCG(cwd) and ZCG(cwd_len). Later accel_getcwd() can use stored value and
149165
* avoid getcwd() call.
@@ -1028,15 +1044,33 @@ char *accel_make_persistent_key_ex(zend_file_handle *file_handle, int path_lengt
10281044
}
10291045
memcpy(ZCG(key) + cur_len, include_path, include_path_len);
10301046
ZCG(key)[key_length] = '\0';
1031-
} else {
1032-
/* not use_cwd */
1033-
key_length = path_length;
1047+
} else {
1048+
/* not use_cwd */
1049+
key_length = path_length;
10341050
if ((size_t)key_length >= sizeof(ZCG(key))) {
10351051
ZCG(key_len) = 0;
10361052
return NULL;
1053+
} else {
1054+
char *alias;
1055+
int alias_len;
1056+
if (is_phar_relative_alias_path(file_handle->filename, &alias, &alias_len)) {
1057+
char *phar_path;
1058+
int phar_path_len;
1059+
if (phar_resolve_alias(alias, alias_len, &phar_path, &phar_path_len TSRMLS_CC) == SUCCESS) {
1060+
int filename_len = strlen(file_handle->filename);
1061+
memcpy(ZCG(key), "phar://", sizeof("phar://") -1);
1062+
memcpy(ZCG(key) + sizeof("phar://") - 1, phar_path, phar_path_len);
1063+
memcpy(ZCG(key) + sizeof("phar://") - 1 + phar_path_len,
1064+
alias + alias_len, filename_len - alias_len - sizeof("phar://") + 2);
1065+
key_length = filename_len + (phar_path_len - alias_len);
1066+
} else {
1067+
memcpy(ZCG(key), file_handle->filename, key_length + 1);
1068+
}
1069+
} else {
1070+
memcpy(ZCG(key), file_handle->filename, key_length + 1);
1071+
}
10371072
}
1038-
memcpy(ZCG(key), file_handle->filename, key_length + 1);
1039-
}
1073+
}
10401074

10411075
*key_len = ZCG(key_len) = key_length;
10421076
return ZCG(key);

0 commit comments

Comments
 (0)