Skip to content

Commit b5c8b91

Browse files
committed
Add capacity check (only in debug mode)
1 parent 91e64af commit b5c8b91

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4765,6 +4765,9 @@ static int accel_finish_startup(void)
47654765

47664766
ZCG(mem_checksum_skip_list) = NULL;
47674767
ZCG(mem_checksum_skip_list_count) = 0;
4768+
#if ZEND_DEBUG
4769+
ZCG(mem_checksum_skip_list_capacity) = 0;
4770+
#endif
47684771

47694772
if (accel_preload(ZCG(accel_directives).preload, in_child) != SUCCESS) {
47704773
ret = FAILURE;

ext/opcache/ZendAccelerator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ typedef struct _zend_accel_globals {
245245

246246
zend_accel_skip_list_entry *mem_checksum_skip_list;
247247
uint32_t mem_checksum_skip_list_count;
248+
/* We don't actually need the capacity because the skip list is preallocated to the right size.
249+
* We only use this in a debug build to check for bugs. If an assertion failure would ever trigger
250+
* for this field, then it's signifies a bug in the persistence code because the calculation and
251+
* actual size don't match. */
252+
#if ZEND_DEBUG
253+
uint32_t mem_checksum_skip_list_capacity;
254+
#endif
248255
} zend_accel_globals;
249256

250257
typedef struct _zend_string_table {

ext/opcache/zend_persist.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ static void mem_checksum_skip_list_add(void *p, uint32_t checked_area_size, uint
9393
ZEND_ASSERT(ZCG(mem_checksum_skip_list) != NULL);
9494
char *base_ptr = (char *) ZCG(current_persistent_script)->mem + sizeof(zend_persistent_script);
9595
ZEND_ASSERT((char *) p >= base_ptr);
96+
#if ZEND_DEBUG
97+
ZEND_ASSERT(ZCG(mem_checksum_skip_list_count) < ZCG(mem_checksum_skip_list_capacity));
98+
#endif
9699
zend_accel_skip_list_entry *entry = &ZCG(mem_checksum_skip_list)[ZCG(mem_checksum_skip_list_count)++];
97100
entry->offset = (char *) p - base_ptr;
98101
entry->checked_area_size = checked_area_size;
@@ -1337,6 +1340,9 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script
13371340

13381341
/* The skip list count is still set by the persist_calc routines, which always precedes a call to this function. */
13391342
ZCG(mem_checksum_skip_list) = safe_emalloc(ZCG(mem_checksum_skip_list_count), sizeof(zend_accel_skip_list_entry), 0);
1343+
#if ZEND_DEBUG
1344+
ZCG(mem_checksum_skip_list_capacity) = ZCG(mem_checksum_skip_list_count);
1345+
#endif
13401346
ZCG(mem_checksum_skip_list_count) = 0;
13411347

13421348
script->mem = ZCG(mem);

0 commit comments

Comments
 (0)