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-13 20:03:31 -07:00
parent 4b0ac5a12b
commit 1d0368d35a
No known key found for this signature in database
GPG key ID: BA0F6CF92356379E
5 changed files with 10 additions and 4 deletions

View file

@ -641,6 +641,12 @@ extern pthread_mutexattr_t my_errorcheck_mutexattr;
#endif
typedef uint64 my_thread_id;
/**
The binary log format limits `my_thread_id` to 32 bits in practice (though
not all `thread_id`s are typed as such, including @ref my_thread_id itself).
@see MDEV-35706
*/
#define MY_THREAD_ID_MAX UINT32_MAX
extern void my_threadattr_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_COMMENT This variable is for internal server use
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 18446744073709551615
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL
READ_ONLY NO

View file

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

View file

@ -9778,7 +9778,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 <algorithm>

View file

@ -1767,7 +1767,7 @@ Sys_pseudo_thread_id(
"pseudo_thread_id",
"This variable is for internal server use",
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);
static bool