From 338a47bb856872f9ab0db94e867333d73279ca85 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 23 Jul 2021 10:27:31 +0200 Subject: [PATCH] Fix bug #63327 Use ZEND_MM_ALIGNED_SIZE for the extra size information. I don't have a relevant system to test, but this should fix the issue as long as required alignment is detected correctly. --- NEWS | 4 ++++ ext/mysqlnd/mysqlnd_alloc.c | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index d1e50dfe270..5c36e386f92 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.1.0beta2 +- MySQLnd: + . Fixed bug #63327 (Crash (Bus Error) in mysqlnd due to wrong alignment). + (Nikita) + - Opcache: . Fixed Bug #81255 (Memory leak in PHPUnit with functional JIT) . Fixed Bug #80959 (infinite loop in building cfg during JIT compilation) diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c index a9c480c0f54..73770417ab6 100644 --- a/ext/mysqlnd/mysqlnd_alloc.c +++ b/ext/mysqlnd/mysqlnd_alloc.c @@ -61,9 +61,10 @@ PHPAPI const char * mysqlnd_debug_std_no_trace_funcs[] = #define __zend_orig_lineno 0 #endif -#define REAL_SIZE(s) (collect_memory_statistics? (s) + sizeof(size_t) : (s)) -#define REAL_PTR(p) (collect_memory_statistics && (p)? (((char *)(p)) - sizeof(size_t)) : (p)) -#define FAKE_PTR(p) (collect_memory_statistics && (p)? (((char *)(p)) + sizeof(size_t)) : (p)) +#define EXTRA_SIZE ZEND_MM_ALIGNED_SIZE(sizeof(size_t)) +#define REAL_SIZE(s) (collect_memory_statistics? (s) + EXTRA_SIZE : (s)) +#define REAL_PTR(p) (collect_memory_statistics && (p)? (((char *)(p)) - EXTRA_SIZE) : (p)) +#define FAKE_PTR(p) (collect_memory_statistics && (p)? (((char *)(p)) + EXTRA_SIZE) : (p)) /* {{{ _mysqlnd_emalloc */ static void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D)