diff options
author | Mitch Hagstrand <mhagstrand@gmail.com> | 2019-10-09 03:38:11 -0500 |
---|---|---|
committer | Joe Watkins <krakjoe@php.net> | 2019-10-14 16:46:42 +0200 |
commit | e2a6bf482faaf0a293bc2dffb530b95d9d3d6408 (patch) | |
tree | 3edbb1777a9e89ebfd97ddc03a42539ef7e22bb1 /ext | |
parent | 900bdcbd0311b13eef5a1b9951ef0e7374fce6f7 (diff) | |
download | php-git-e2a6bf482faaf0a293bc2dffb530b95d9d3d6408.tar.gz |
Fix checksum calculation for opcache
Diffstat (limited to 'ext')
-rw-r--r-- | ext/opcache/zend_accelerator_util_funcs.c | 14 | ||||
-rw-r--r-- | ext/opcache/zend_accelerator_util_funcs.h | 2 | ||||
-rw-r--r-- | ext/opcache/zend_file_cache.c | 9 |
3 files changed, 14 insertions, 11 deletions
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index 95e9c504a0..a765d2cb65 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -735,11 +735,11 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script, #define ADLER32_DO8(buf, i) ADLER32_DO4(buf, i); ADLER32_DO4(buf, i + 4); #define ADLER32_DO16(buf) ADLER32_DO8(buf, 0); ADLER32_DO8(buf, 8); -unsigned int zend_adler32(unsigned int checksum, signed char *buf, uint32_t len) +unsigned int zend_adler32(unsigned int checksum, unsigned char *buf, uint32_t len) { unsigned int s1 = checksum & 0xffff; unsigned int s2 = (checksum >> 16) & 0xffff; - signed char *end; + unsigned char *end; while (len >= ADLER32_NMAX) { len -= ADLER32_NMAX; @@ -777,15 +777,15 @@ unsigned int zend_adler32(unsigned int checksum, signed char *buf, uint32_t len) unsigned int zend_accel_script_checksum(zend_persistent_script *persistent_script) { - signed char *mem = (signed char*)persistent_script->mem; + unsigned char *mem = (unsigned char*)persistent_script->mem; size_t size = persistent_script->size; size_t persistent_script_check_block_size = ((char *)&(persistent_script->dynamic_members)) - (char *)persistent_script; unsigned int checksum = ADLER32_INIT; - if (mem < (signed char*)persistent_script) { - checksum = zend_adler32(checksum, mem, (signed char*)persistent_script - mem); - size -= (signed char*)persistent_script - mem; - mem += (signed char*)persistent_script - mem; + if (mem < (unsigned char*)persistent_script) { + checksum = zend_adler32(checksum, mem, (unsigned char*)persistent_script - mem); + size -= (unsigned char*)persistent_script - mem; + mem += (unsigned char*)persistent_script - mem; } zend_adler32(checksum, mem, persistent_script_check_block_size); diff --git a/ext/opcache/zend_accelerator_util_funcs.h b/ext/opcache/zend_accelerator_util_funcs.h index 5d7834abe7..b34e0f47fa 100644 --- a/ext/opcache/zend_accelerator_util_funcs.h +++ b/ext/opcache/zend_accelerator_util_funcs.h @@ -37,7 +37,7 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script, #define ADLER32_INIT 1 /* initial Adler-32 value */ -unsigned int zend_adler32(unsigned int checksum, signed char *buf, uint32_t len); +unsigned int zend_adler32(unsigned int checksum, unsigned char *buf, uint32_t len); unsigned int zend_accel_script_checksum(zend_persistent_script *persistent_script); diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index 39de839e47..dcf8ea9fa0 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -868,7 +868,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, int in_shm) zend_shared_alloc_destroy_xlat_table(); info.checksum = zend_adler32(ADLER32_INIT, buf, script->size); - info.checksum = zend_adler32(info.checksum, (signed char*)ZSTR_VAL((zend_string*)ZCG(mem)), info.str_size); + info.checksum = zend_adler32(info.checksum, (unsigned char*)ZSTR_VAL((zend_string*)ZCG(mem)), info.str_size); #ifdef HAVE_SYS_UIO_H vec[0].iov_base = &info; @@ -1371,6 +1371,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; + unsigned int actual_checksum; int ok; if (!full_path) { @@ -1458,8 +1459,8 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl /* verify checksum */ if (ZCG(accel_directives).file_cache_consistency_checks && - zend_adler32(ADLER32_INIT, mem, info.mem_size + info.str_size) != info.checksum) { - zend_accel_error(ACCEL_LOG_WARNING, "corrupted file '%s'\n", filename); + (actual_checksum = zend_adler32(ADLER32_INIT, mem, info.mem_size + info.str_size)) != info.checksum) { + zend_accel_error(ACCEL_LOG_WARNING, "corrupted file '%s' excepted checksum: 0x%08x actual checksum: 0x%08x\n", filename, info.checksum, actual_checksum); unlink(filename); zend_arena_release(&CG(arena), checkpoint); efree(filename); @@ -1545,6 +1546,8 @@ use_process_mem: zend_accel_hash_update(&ZCSG(hash), ZSTR_VAL(script->script.filename), ZSTR_LEN(script->script.filename), 0, script); zend_shared_alloc_unlock(); + zend_accel_error(ACCEL_LOG_INFO, "File cached script loaded into memory '%s'", ZSTR_VAL(script->script.filename)); + zend_arena_release(&CG(arena), checkpoint); } efree(filename); |