Skip to content

MDEV-42240 Handle empty strings before case conversion - #6147

Open
chaitanya-bhardwaj wants to merge 1 commit into
MariaDB:11.4from
chaitanya-bhardwaj:fix-42240-empty-case-conversion
Open

chaitanya-bhardwaj wants to merge 1 commit into
MariaDB:11.4from
chaitanya-bhardwaj:fix-42240-empty-case-conversion

Conversation

@chaitanya-bhardwaj

@chaitanya-bhardwaj chaitanya-bhardwaj commented Nov 14, 2026 •

Copy link
Copy Markdown
  • The Jira issue number for this PR is: MDEV-42240

Description

When REGEXP_SUBSTR() finds no match, or SFORMAT() produces no text, the empty result can have a NULL buffer. LOWER(), UPPER() and their aliases pass it to the case converter, which expects a valid pointer even when the string is empty. Both cases crash on a debug build.

Handle empty strings before calling the converter, using the existing make_empty_result() helper. This keeps the character set and gives the result a valid buffer. Reset null_value so an empty string after a NULL row doesn't get returned as NULL. NULL inputs and non-empty strings keep their existing behavior.

Release Notes

Prevent a debug-server crash when LOWER(), UPPER(), LCASE() or UCASE() receives an empty result from REGEXP_SUBSTR() or SFORMAT().

How can this PR be tested?

The new main.ctype_case_empty test catches the crash on the original 11.4 server and passes in normal, PS, cursor and view modes with this change. It covers both functions, the aliases, utf8mb4 and latin1, table rows, WHERE conditions, repeated prepared execution, NULL and non-empty values. Seven related existing tests passed too. The full suite, Windows and UBSan haven't been tested.

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development branch.
  • This is a bug fix and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

When REGEXP_SUBSTR() finds no match, or SFORMAT() produces no text, the
empty result can have a NULL buffer. LOWER(), UPPER() and their aliases
pass it to the case converter, which expects a valid pointer even when
the string is empty. Both cases crash on an 11.4 debug build.

Handle empty strings before calling the converter. Use the existing
make_empty_result() helper to keep the character set and give the result
a valid buffer. Reset null_value so an empty string after a NULL row
doesn't get returned as NULL. NULL inputs and non-empty strings keep
their existing behavior. No new syntax or options are needed.

The new test checks LOWER(), UPPER(), LCASE() and UCASE() with utf8mb4 and
latin1, table rows, WHERE conditions, repeated prepared execution, NULL
and non-empty values. It catches the crash on the original server and
passes in normal, PS, cursor and view modes with no exclusions. Seven
related existing tests passed too. The full suite, Windows and UBSan
haven't been tested.

Assisted-by: Codex:gpt-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant