Skip to content

Instantly share code, notes, and snippets.

@dstogov
Created December 21, 2017 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstogov/69e9a08038dcaf3c2e72ea4b1676242c to your computer and use it in GitHub Desktop.
Save dstogov/69e9a08038dcaf3c2e72ea4b1676242c to your computer and use it in GitHub Desktop.
diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c
index dea427fcaf..98a170f41f 100644
--- a/ext/opcache/zend_file_cache.c
+++ b/ext/opcache/zend_file_cache.c
@@ -227,8 +227,17 @@ static void *zend_file_cache_unserialize_interned(zend_string *str, int in_shm)
if (in_shm) {
ret = accel_new_interned_string(str);
if (ret == str) {
+ /* We have to create new SHM allocated string */
+ size_t size = _ZSTR_STRUCT_SIZE(ZSTR_LEN(str));
+ ret = zend_shared_alloc(size);
+ if (!ret) {
+ zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM);
+ LONGJMP(*EG(bailout), FAILURE);
+ }
+ memcpy(ret, str, size);
/* String wasn't interned but we will use it as interned anyway */
- GC_FLAGS(ret) |= IS_STR_INTERNED | IS_STR_PERMANENT;
+ GC_REFCOUNT(ret) = 1;
+ GC_TYPE_INFO(ret) = IS_STRING | ((IS_STR_INTERNED | IS_STR_PERSISTENT | IS_STR_PERMANENT) << 8);
}
} else {
ret = str;
@@ -1288,6 +1297,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
zend_accel_hash_entry *bucket;
void *mem, *checkpoint, *buf;
int cache_it = 1;
+ int ok;
if (!full_path) {
return NULL;
@@ -1429,7 +1439,24 @@ use_process_mem:
ZCG(mem) = ((char*)mem + info.mem_size);
script = (zend_persistent_script*)((char*)buf + info.script_offset);
script->corrupted = !cache_it; /* used to check if script restored to SHM or process memory */
- zend_file_cache_unserialize(script, buf);
+
+ ok = 1;
+ zend_try {
+ zend_file_cache_unserialize(script, buf);
+ } zend_catch {
+ ok = 0;
+ } zend_end_try();
+ if (!ok) {
+ if (cache_it) {
+ zend_shared_alloc_unlock();
+ goto use_process_mem;
+ } else {
+ zend_arena_release(&CG(arena), checkpoint);
+ efree(filename);
+ return NULL;
+ }
+ }
+
script->corrupted = 0;
if (cache_it) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment