MDEV-39559: Assertion b failed in my_strnncoll_xxxx_nopad_ci#5215
MDEV-39559: Assertion b failed in my_strnncoll_xxxx_nopad_ci#5215raghunandanbhat wants to merge 1 commit into
b failed in my_strnncoll_xxxx_nopad_ci#5215Conversation
There was a problem hiding this comment.
Code Review
This pull request addresses MDEV-39559 by adding assertions and null checks for blob pointers in Field_blob::cmp, Field_blob::cmp_prefix, and Field_blob::key_cmp within sql/field.cc, as well as adding corresponding test cases. The review feedback points out a potential out-of-bounds memory read in release builds (where DBUG_ASSERT is disabled) if a blob pointer is null but its length is non-zero. To prevent this, it is recommended to explicitly reset the corresponding length variables to 0 when substituting null pointers with an empty string.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Problem:
When verifying a `UNIQUE` constraint over an empty BLOB/TEXT column,
`Field_blob::cmp(a_ptr, b_ptr)` extracts a NULL data pointer (with
length 0) from the record slot and forwards it to the charset-level
comparison, which asserts non-NULL pointers (added in MDEV-35717).
A zero-length blob is allowed to have a NULL data pointer in its
record slot; `Field_blob::val_decimal()` already treats (NULL, 0) as
an empty value. The comparison paths missed that substitution.
Fix:
- In `Field_blob::cmp(a_ptr, b_ptr)`, `Field_blob::cmp_prefix()` and
`Field_blob::key_cmp(key_ptr, max_key_length)`, substitute "" for a
NULL data pointer before delegating to the comparison.
- Add a debug assert in each of the above functions to document the
invariant that a NULL pointer is only valid alongside zero length
and (NULL, length>0) is invalid.
e112eaf to
ad5c9d6
Compare
fixes MDEV-39559
Problem
When verifying a
UNIQUEconstraint over an empty BLOB/TEXT column,Field_blob::cmp(a_ptr, b_ptr)extracts a NULL data pointer (with length 0) from the record slot and forwards it to the charset-level comparison, which asserts non-NULL pointers (added in MDEV-35717).A zero-length blob is allowed to have a NULL data pointer in its record slot;
Field_blob::val_decimal()already treats (NULL, 0) as an empty value. The comparison paths missed that substitution.Fix
Field_blob::cmp(a_ptr, b_ptr),Field_blob::cmp_prefix()andField_blob::key_cmp(key_ptr, max_key_length), substitute "" for a NULL data pointer before delegating to the comparison.