Repository navigation
MDEV-42240 Handle empty strings before case conversion - #6147
Open
chaitanya-bhardwaj wants to merge 1 commit into
Open
chaitanya-bhardwaj wants to merge 1 commit into
chaitanya-bhardwaj wants to merge 1 commit into
Conversation
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
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.
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
PR quality check