MDEV-41179 MAX_KEY_PARTS ranges in select causing SEGV - #5782
Open
mariadb-RexJohnston wants to merge 1 commit into
Open
mariadb-RexJohnston wants to merge 1 commit into
mariadb-RexJohnston wants to merge 1 commit into
Conversation
mariadb-RexJohnston
requested review from
DaveGosselin-MariaDB and
Olernov
and removed request for
DaveGosselin-MariaDB
September 29, 2026 00:02
When a select containing 32 ranges is made on a table containing a
compound key with 32 parts, the range optimizer can run off the end
of a stack variable, invalidly overwriting subsequent stack variables.
In the struct st_sel_arg_range_seq, we have an array
RANGE_SEQ_ENTRY stack[MAX_REF_PARTS];
MAX_REF_PARTS is 32.
check_quick_select
/ sel_arg_range_seq_init
initialises stack[0] as NOT a key part
/ sel_arg_range_seq_next
iterates through the key parts, adding key part n to stack[n+1]
key part #32 gets referenced by step_down_to(), setting seq->i off the
end of the array.
The above change has exposed an issue with key length calculation
on MS Windows. The field is a ulong and with all 32 key parts
wanted, we calculate this as (1UL << 32) - 1. The first part of
the calculation overflows the field. The result is undefined in C++.
Fix: change key_part_map to 64 bits long, so it is the same on Linux
and MS Windows.
mariadb-RexJohnston
force-pushed
the
10.11-MDEV-41179
branch
from
September 29, 2026 01:01
751307b to
5e0b205
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a select containing 32 ranges is made on a table containing a compound key with 32 parts, the range optimizer can run off the end of a stack variable, invalidly overwriting subsequent stack variables.
In the struct st_sel_arg_range_seq, we have an array
RANGE_SEQ_ENTRY stack[MAX_REF_PARTS];
MAX_REF_PARTS is 32.
check_quick_select
/ sel_arg_range_seq_init
initialises stack[0] as NOT a key part
/ sel_arg_range_seq_next
iterates through the key parts, adding key part n to stack[n+1]
key part #32 gets referenced by step_down_to(), setting seq->i off the end of the array.
The above change has exposed an issue with key length calculation on MS Windows. The field is a ulong and with all 32 key parts wanted, we calculate this as (1UL << 32) - 1. The first part of the calculation overflows the field. The result is undefined in C++.
Fix: change key_part_map to 64 bits long, so it is the same on Linux
and MS Windows.