Skip to content

fix: validate projection name length at DDL time to prevent unwritable tables - #112741

Closed
waterWang wants to merge 1 commit into
ClickHouse:masterfrom
waterWang:fix/projection-name-length
Closed

waterWang wants to merge 1 commit into
ClickHouse:masterfrom
waterWang:fix/projection-name-length

Conversation

@waterWang

Copy link
Copy Markdown

Closes #112714

A projection whose name is longer than 250 characters is accepted by CREATE TABLE
and ALTER TABLE ... ADD PROJECTION, but every INSERT into that table then fails
with Code: 1001, STD_EXCEPTION (ENAMETOOLONG). The directory name is <name>.proj,
so the raw name must fit in NAME_MAX - strlen(".proj") = 255 - 5 = 250.

Changes:

  1. Added extern const int ARGUMENT_OUT_OF_BOUND error code declaration
  2. Added name length validation in ProjectionsDescription::add() that throws
    ARGUMENT_OUT_OF_BOUND at DDL time, consistent with how
    DatabaseOnDisk::checkTableNameLength validates table names

Verification boundary:

projection name length <name>.proj Before fix After fix
249 254 OK OK
250 255 OK OK
251 256 Code: 1001, STD_EXCEPTION Code: 69, ARGUMENT_OUT_OF_BOUND

…e tables

A projection whose name is longer than 250 characters is accepted by CREATE TABLE
and ALTER TABLE ... ADD PROJECTION, but every INSERT into that table then fails
with Code: 1001, STD_EXCEPTION (ENAMETOOLONG). The directory name is <name>.proj,
so the name must fit in NAME_MAX - strlen(".proj") = 255 - 5 = 250.

Add validation in ProjectionsDescription::add() to throw ARGUMENT_OUT_OF_BOUND
at DDL time, consistent with how DatabaseOnDisk::checkTableNameLength validates
table names.

Closes ClickHouse#112714
@CLAassistant

CLAassistant commented Jul 31, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


water seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@@ -860,6 +861,17 @@ void ProjectionsDescription::add(ProjectionDescription && projection, const Stri
ErrorCodes::ILLEGAL_PROJECTION, "Cannot add projection {}: projection with this name already exists", projection.name);
}

/// Validate projection name length: the directory name is <name>.proj,
/// so the name must fit in NAME_MAX - strlen(".proj") = 255 - 5 = 250.
constexpr size_t max_projection_name_length = 250;

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.

Please check against NAME_MAX macro minus .proj suffix. Check that both create table and alter table with projection paths are covered with a test.

@alexey-milovidov alexey-milovidov changed the title fix: validate projection name length at DDL time to prevent unwritable tables [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] fix: validate projection name length at DDL time to prevent unwritable tables Jul 31, 2026
@alexey-milovidov alexey-milovidov added close in a month if not active This will be closed in case of no information spam labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close in a month if not active This will be closed in case of no information spam

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long projection names gives bad insert errors

4 participants