Skip to content

Limit the number of array dimensions reported by PostgreSQL - #131734

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-postgresql-array-dimensions-limit
Nov 17, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-postgresql-array-dimensions-limit

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

The number of dimensions of a PostgreSQL array (attndims or array_ndims) comes from the remote server and was used without a limit, each dimension adding a level of Array. A huge number produced a type so deep that working with it exhausted the stack and crashed the server, and a negative number from array_ndims made the loop run about 2^31 times. PostgreSQL itself allows at most 6 dimensions; refuse anything outside 1..100.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a possible crash of the PostgreSQL table engine, table function and database engine when the remote server reports an absurd number of array dimensions.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131734]

Version info

  • Merged into: 26.11.1.2516-master (included in 26.11 and later)
  • Backported to: 26.10.5.47, 26.9.31.12, 26.8.39.11, 26.3.66.8

The number of dimensions of a PostgreSQL array (`attndims` or `array_ndims`) comes from the remote server and was used without a limit, each dimension adding a level of `Array`. A huge number produced a type so deep that working with it exhausted the stack and crashed the server, and a negative number from `array_ndims` made the loop run about 2^31 times. PostgreSQL itself allows at most 6 dimensions; refuse anything outside 1..100.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6830258]

Summary: ✅


AI Review

Summary

The PR limits PostgreSQL-reported array dimensions to 1–100 before constructing nested Array types, covering both attndims and array_ndims. The added test_postgres_ndim_out_of_range exercises oversized catalog dimensions; the signed recheck path uses the same validated helper. The earlier coverage concern is addressed and its thread is resolved. No remaining findings at head 68302585dd93163c91004f90b21c90088f983592.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-postgresql PostgreSQL-specific integration (table engine/function, logical replication bridge). label Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 68302585d with master f0ee6ba9f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

Address review: cover an oversized `attndims` reported by the remote server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
Merged via the queue into master with commit 6c99300 Nov 17, 2026
192 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-postgresql-array-dimensions-limit branch November 17, 2026 02:50
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131734 to 26.10: Limit the number of array dimensions reported by PostgreSQL
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131734 to 26.9: Limit the number of array dimensions reported by PostgreSQL
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131734 to 26.8: Limit the number of array dimensions reported by PostgreSQL
PedroTadim added a commit that referenced this pull request Nov 17, 2026
Backport #131734 to 26.3: Limit the number of array dimensions reported by PostgreSQL
mkmkme pushed a commit to Altinity/ClickHouse that referenced this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-postgresql PostgreSQL-specific integration (table engine/function, logical replication bridge). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants