Skip to content

MDEV-39278 Validate .cfg file parser string lengths in InnoDB import#4913

Merged
gkodinov merged 1 commit intoMariaDB:10.11from
FaramosCZ:MDEV-39278
Apr 8, 2026
Merged

MDEV-39278 Validate .cfg file parser string lengths in InnoDB import#4913
gkodinov merged 1 commit intoMariaDB:10.11from
FaramosCZ:MDEV-39278

Conversation

@FaramosCZ
Copy link
Copy Markdown
Contributor

Replace overly permissive or missing length limits in the .cfg metadata file parser (used by ALTER TABLE ... IMPORT TABLESPACE) with correct constants:

  • Field/index/column names: NAME_LEN + 1 (193 bytes including NUL), matching the maximum identifier length defined in mysql_com.h. Replaces the hardcoded 128 for columns (with FIXME) and OS_FILE_MAX_PATH (4000) for index names. Adds missing validation for field names.

  • Hostname: HOSTNAME_LENGTH + 1 (256), consistent with MariaDB's own hostname limit defined in mysql_com.h. RFC 1035 defines the textual DNS name limit as 253 characters (254 with NUL), but HOSTNAME_LENGTH (255) is based on the RFC 1034 wire-format limit of 255 octets. Using HOSTNAME_LENGTH avoids rejecting .cfg files exported from servers with valid 254-255 character hostnames.

  • Table name: MAX_FULL_NAME_LEN + 1 (655 bytes including NUL), since the .cfg file stores the full db/table name (written by row0quiesce.cc as table->name.m_name).

Without these checks, a crafted .cfg file could specify lengths up to 2^32 via the 4-byte mach_read_from_4() length prefix, causing excessive memory allocation.

@FaramosCZ FaramosCZ mentioned this pull request Apr 7, 2026
@FaramosCZ FaramosCZ force-pushed the MDEV-39278 branch 5 times, most recently from 9091fb0 to ebef28b Compare April 7, 2026 21:27
@FaramosCZ FaramosCZ marked this pull request as ready for review April 8, 2026 00:26
Copy link
Copy Markdown
Contributor

@dr-m dr-m left a comment

Choose a reason for hiding this comment

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

I see that this is pretty horrible code, which you fixed in a minimal way. Given that the change is so small, I think that should count as a bug fix and target the earliest major version branch where such fixes are accepted. That would be 10.11, because by our current policy we only fix demonstrated crashing bugs in the 10.6 release series, which will soon reach its end of life.

I hope that some day we’ll have a chance to implement MDEV-11658 and make the .cfg files redundant by storing all the metadata that is omitted from .frm files in the .ibd files themselves. This is why I don’t think it would make sense to invest time in cleaning this up further. Cleanup ideas would include making row_import_cfg_read_string() issue a single fread, and having row_import_cfg_read_index_fields(() read into an implicitly aligned uint32_t row[3] and decoding the data with my_betoh32(row[0]) and so on.

Can you please rebase this on the 10.11 branch?

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Apr 8, 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.

Is it possible to do even some minimal testing? E.g. have a cooked .cfg file with a large value and see it rejected?

Otherwise, please keep working with Marko on the final review. I side with his request to rebase this to 10.11.

@FaramosCZ FaramosCZ marked this pull request as draft April 8, 2026 09:48
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 8, 2026

CLA assistant check
All committers have signed the CLA.

@FaramosCZ FaramosCZ changed the base branch from main to 10.11 April 8, 2026 09:51
Comment thread storage/innobase/row/row0import.cc
Replace overly permissive or missing length limits in the .cfg
metadata file parser (used by ALTER TABLE ... IMPORT TABLESPACE)
with correct constants:

- Field/index/column names: NAME_LEN + 1 (193 bytes including
  NUL), matching the maximum identifier length defined in
  mysql_com.h. Replaces the hardcoded 128 for columns (with
  FIXME) and OS_FILE_MAX_PATH (4000) for index names. Adds
  missing validation for field names.
- Hostname: HOSTNAME_LENGTH + 1 (256), consistent with
  MariaDB's own hostname limit defined in mysql_com.h.
  RFC 1035 defines the textual DNS name limit as 253
  characters (254 with NUL), but HOSTNAME_LENGTH (255) is
  based on the RFC 1034 wire-format limit of 255 octets.
  Using HOSTNAME_LENGTH avoids rejecting .cfg files exported
  from servers with valid 254-255 character hostnames.
- Table name: MAX_FULL_NAME_LEN + 1 (655 bytes including NUL),
  since the .cfg file stores the full db/table name (written
  by row0quiesce.cc as table->name.m_name).

Without these checks, a crafted .cfg file could specify lengths
up to 2^32 via the 4-byte mach_read_from_4() length prefix,
causing excessive memory allocation.

Use ib_senderrf() instead of ib_errf() for reporting validation
failures. ib_errf() pre-formats its message into a single string
and passes it to ib_senderrf(), but ER_IO_READ_ERROR expects
three arguments (%lu, %s, %s). Using ib_senderrf() directly
with the correct arguments avoids this format mismatch.
The pre-existing column name check had the same ib_errf() misuse
and is corrected here as well.

The test covers hostname and table name length validation.
Column name, index name, and field name length validation
are not tested because their offsets are deep in the .cfg
binary format and would require walking past variable-length
sections (autoinc, page size, flags, column/index metadata).

Co-Authored-By: Claude AI <noreply@anthropic.com>
@FaramosCZ
Copy link
Copy Markdown
Contributor Author

FaramosCZ commented Apr 8, 2026

I rebased to 10.11, switched to the better ib_senderrf, used 0UL and attempted to create a test.

@FaramosCZ FaramosCZ marked this pull request as ready for review April 8, 2026 12:17
@FaramosCZ FaramosCZ requested a review from gkodinov April 8, 2026 12:17
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.

LGTM. Thanks for working on the test!

@gkodinov gkodinov merged commit ddc6874 into MariaDB:10.11 Apr 8, 2026
17 of 18 checks passed
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.

4 participants