Skip to content

MDEV-39767: include name pool size in dynamic column get bounds check#5129

Open
jmestwa-coder wants to merge 1 commit into
MariaDB:mainfrom
jmestwa-coder:dyncol-named-nmpool-bounds
Open

MDEV-39767: include name pool size in dynamic column get bounds check#5129
jmestwa-coder wants to merge 1 commit into
MariaDB:mainfrom
jmestwa-coder:dyncol-named-nmpool-bounds

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Found by fuzzing COLUMN_GET() with malformed blobs. In the named format
find_column() only checks that the column directory fits the record, not
the name pool, so init_read_hdr()'s data_size wraps around and read_name()
walks the name pointer past the buffer. mariadb_dyncol_check() and
mariadb_dyncol_unpack() already fold nmpool_size into this check; do the
same on the get path.

Copy link
Copy Markdown

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

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 updates the bounds check in find_column within mysys/ma_dyncol.c to include hdr->nmpool_size, preventing out-of-bounds reads when handling named-format records. It also introduces a new unit test, test_named_format_oob_nmpool, to verify this behavior. The reviewer noted that the pointer addition in the new bounds check could lead to pointer wrapping or integer overflow if the sizes are maliciously crafted, and suggested a safer validation approach using subtraction to prevent potential bypasses.

Comment thread mysys/ma_dyncol.c
Comment on lines +2104 to 2105
if (hdr->header + hdr->header_size + hdr->nmpool_size > hdr->data_end)
return TRUE;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The pointer addition hdr->header + hdr->header_size + hdr->nmpool_size can lead to pointer wrapping or integer overflow if hdr->header_size and hdr->nmpool_size are extremely large or maliciously crafted. This could bypass the bounds check and result in an out-of-bounds read. To prevent this, perform the bounds check by comparing the sizes against the remaining buffer space without performing additions that could overflow.

  if (hdr->header_size > (size_t)(hdr->data_end - hdr->header) ||
      hdr->nmpool_size > (size_t)(hdr->data_end - hdr->header) - hdr->header_size)
    return TRUE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd second Gemini here. It's better to be safe.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label May 27, 2026
@gkodinov gkodinov changed the title include name pool size in dynamic column get bounds check MDEV-39767: include name pool size in dynamic column get bounds check May 27, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. This is a preliminary review.

LGTM. Thanks for the unit test! The improvement suggested by the AI reviewer is a good idea.

Please stand by for the final review.

Comment thread mysys/ma_dyncol.c
Comment on lines +2104 to 2105
if (hdr->header + hdr->header_size + hdr->nmpool_size > hdr->data_end)
return TRUE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd second Gemini here. It's better to be safe.

@gkodinov gkodinov requested a review from midenok May 27, 2026 08:00
@gkodinov gkodinov requested review from sanja-byelkin and removed request for midenok May 27, 2026 08:06
@gkodinov gkodinov assigned sanja-byelkin and unassigned midenok May 27, 2026
@vuvova
Copy link
Copy Markdown
Member

vuvova commented May 27, 2026

likely already fixed in 9a3e153

Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Please backport to 10.6: this is a bug and it needs to be fixed in the lowest affected version.

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.

5 participants