MDEV-35646: Limit pseudo_thread_id to UINT32_MAX

Although the `my_thread_id` type is 64 bits, binlog format specs
limits it to 32 bits in practice. (See also: MDEV-35706)

The writable SQL variable `pseudo_thread_id` didn’t realize this though
and had a range of `ULONGLONG_MAX` (at least `UINT64_MAX` in C/C++).
It consequentially accepted larger values silently, but only the lower
32 bits of whom gets binlogged; this could lead to inconsistency.

Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
This commit is contained in:
ParadoxV5 2025-01-16 20:57:01 -07:00
parent 782c4b94f0
commit cbb24d9aa5
5 changed files with 11 additions and 4 deletions

View file

@ -641,6 +641,13 @@ extern pthread_mutexattr_t my_errorcheck_mutexattr;
#endif #endif
typedef uint64 my_thread_id; typedef uint64 my_thread_id;
/**
Long-standing formats (such as the client-server protocol and the binary log)
hard-coded `my_thread_id` to 32 bits in practice. (Though not all
`thread_id`s are typed as such, @ref my_thread_id itself among those.)
@see MDEV-35706
*/
#define MY_THREAD_ID_MAX UINT32_MAX
extern void my_threadattr_global_init(void); extern void my_threadattr_global_init(void);
extern my_bool my_thread_global_init(void); extern my_bool my_thread_global_init(void);

View file

@ -2877,7 +2877,7 @@ VARIABLE_SCOPE SESSION ONLY
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT This variable is for internal server use VARIABLE_COMMENT This variable is for internal server use
NUMERIC_MIN_VALUE 0 NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 18446744073709551615 NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO

View file

@ -3037,7 +3037,7 @@ VARIABLE_SCOPE SESSION ONLY
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT This variable is for internal server use VARIABLE_COMMENT This variable is for internal server use
NUMERIC_MIN_VALUE 0 NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 18446744073709551615 NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO

View file

@ -9770,7 +9770,7 @@ void init_server_psi_keys(void)
*/ */
static my_thread_id thread_id_max= UINT_MAX32; static my_thread_id thread_id_max= MY_THREAD_ID_MAX;
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>

View file

@ -1767,7 +1767,7 @@ Sys_pseudo_thread_id(
"pseudo_thread_id", "pseudo_thread_id",
"This variable is for internal server use", "This variable is for internal server use",
SESSION_ONLY(pseudo_thread_id), SESSION_ONLY(pseudo_thread_id),
NO_CMD_LINE, VALID_RANGE(0, ULONGLONG_MAX), DEFAULT(0), NO_CMD_LINE, VALID_RANGE(0, MY_THREAD_ID_MAX), DEFAULT(0),
BLOCK_SIZE(1), NO_MUTEX_GUARD, IN_BINLOG); BLOCK_SIZE(1), NO_MUTEX_GUARD, IN_BINLOG);
static bool static bool