From 62f972f32448d139b06938986518725192f1928f Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 23 Oct 2026 13:45:06 +0300 Subject: [PATCH] Fix a UBSAN runtime error on MacOSX. When running on MacOSX with `-DWITH_UBSAN` I get the following error at runtime: ``` 2026-10-23 13:28:31 0 [Note] InnoDB: Number of transaction pools: 1 2026-10-23 13:28:31 0 [Note] InnoDB: Using generic crc32 instructions 2026-10-23 13:28:31 0 [Note] InnoDB: innodb_buffer_pool_size_max=8388608m, innodb_buffer_pool_size=128m 2026-10-23 13:28:31 0 [Note] InnoDB: Completed initialization of buffer pool 2026-10-23 13:28:31 0 [Note] InnoDB: End of log at LSN=51660 2026-10-23 13:28:31 0 [Note] InnoDB: 128 rollback segments are active. 2026-10-23 13:28:31 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1" 2026-10-23 13:28:31 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ... 2026-10-23 13:28:31 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB. 2026-10-23 13:28:31 0 [Note] InnoDB: log sequence number 51660; transaction id 14 2026-10-23 13:28:31 0 [Note] InnoDB: Loading buffer pool(s) from /Users/gkodinov/dev/mdev-35715/bld/x/ib_buffer_pool 2026-10-23 13:28:31 0 [Note] Plugin 'FEEDBACK' is disabled. /Users/gkodinov/dev/mdev-35715/mysys/my_stack.c:74:38: runtime error: addition of unsigned offset to 0x00016bcc0050 overflowed to 0x00016b1c2050 ``` This is caused by STACK_DIRECTION being negative and, when multiplied by an unsigned, being converted to a large unsigned before the multiplication. Change stack_size type from size_t to ssize_t to avoid this. --- mysys/my_stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysys/my_stack.c b/mysys/my_stack.c index b32925c8f6c..87d18f78f87 100644 --- a/mysys/my_stack.c +++ b/mysys/my_stack.c @@ -71,5 +71,5 @@ extern void my_get_stack_bounds(void **stack_start, void **stack_end, *stack_start= my_get_stack_pointer(fallback_stack_start); stack_size= (fallback_stack_size - MY_MIN(fallback_stack_size, MY_STACK_SAFE_MARGIN)); - *stack_end= (char *)(*stack_start) + stack_size * STACK_DIRECTION; + *stack_end= (char *)(*stack_start) + ((ssize_t)stack_size) * STACK_DIRECTION; }