Skip to content
/ server Public

MDEV-37640: Crash at String::append in json_normalize#4728

Open
abhishek593 wants to merge 1 commit intoMariaDB:10.11from
abhishek593:MDEV-37640
Open

MDEV-37640: Crash at String::append in json_normalize#4728
abhishek593 wants to merge 1 commit intoMariaDB:10.11from
abhishek593:MDEV-37640

Conversation

@abhishek593
Copy link

Item_func_json_normalize::val_str() failed to initialize the character set of the result buffer. In certain contexts, the buffer can be a zero-initialized String object with a NULL charset. This led to a null pointer dereference in String::append(), which relies on the charset information.

Fixed by explicitly setting the buffer's charset to the item's collation before appending the normalized JSON string.

@grooverdan grooverdan added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 4, 2026
@grooverdan
Copy link
Member

Does this happen to resolve MDEV-33984 too? If so its test case could be included too.

@abhishek593
Copy link
Author

@grooverdan The fix is the same, but instead in Item_func_json_keys::val_str. I was thinking to open another PR since the fix version for that is 10.6. Should I change that in this PR itself?

@grooverdan
Copy link
Member

@grooverdan The fix is the same, but instead in Item_func_json_keys::val_str.

Great

I was thinking to open another PR since the fix version for that is 10.6. Should I change that in this PR itself?

It is a bit anomalous that one crash as a fix version of 10.6 and the other 10.11.

As its so close, can you just push the MDEV-33984 fix onto this branch and leave as 10.11 for now. It means there's one less merge conflict in tests and since the problems are so similar it easier to review if both are in memory at the same time.

Thanks @abhishek593. Great seeing your work to correct all these old JSON bugs.

This also fixes MDEV-33984. Item_func_json_normalize::val_str()
and Item_func_json_keys::val_str failed to initialize the character
set of the result buffer. In certain contexts, the buffer can be a
zero-initialized String object with a NULL charset. This led to a null
pointer dereference in String::append(), which relies on the charset
information.

Fixed by explicitly setting the buffer's charset to the item's
collation before appending the normalized JSON string.
@abhishek593
Copy link
Author

@grooverdan Thanks for the kind words. I've updated the PR to also include the fix for MDEV-33984.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants