Skip to content

MDEV-39559: Assertion b failed in my_strnncoll_xxxx_nopad_ci#5215

Open
raghunandanbhat wants to merge 1 commit into
11.8from
11.8-mdev-39559
Open

MDEV-39559: Assertion b failed in my_strnncoll_xxxx_nopad_ci#5215
raghunandanbhat wants to merge 1 commit into
11.8from
11.8-mdev-39559

Conversation

@raghunandanbhat

Copy link
Copy Markdown
Contributor

fixes MDEV-39559

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sql/field.cc Outdated
Comment thread sql/field.cc Outdated
Comment thread sql/field.cc Outdated
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant