Skip to content

Fix out-of-bounds access in getRequiredHeaderPositions for lazy materialization - #101144

Merged
alexey-milovidov merged 8 commits into
masterfrom
fix-lazy-materialization-oob
Apr 25, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
fix-lazy-materialization-oob

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 30, 2026 •

Copy link
Copy Markdown
Member

Fix out-of-bounds access in getRequiredHeaderPositions for lazy materialization.

The loop at line 108 iterated required_output_positions.size() - num_outputs times, accessing non_mapped[i] without checking i < non_mapped.size(). When the DAG has fewer outputs than inputs (e.g., when columns are removed by an expression), num_outputs can be smaller than expected, causing the loop to exceed non_mapped bounds and trigger a SIGABRT in debug builds.

Add i < non_mapped.size() as an additional loop bound.

CI failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100948&sha=7727d7282d1d05a1fcd6c1f9076aee1f066b96e5&name_0=PR&name_1=Stress%20test%20%28amd_debug%29
#100948

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix out-of-bounds access in lazy materialization optimization that could cause an exception in debug builds.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.80 (included in 26.5 and later)
  • Backported to: 26.3.33.14

…erialization

The loop at line 108 iterated `required_output_positions.size() - num_outputs`
times, accessing `non_mapped[i]` without checking `i < non_mapped.size()`.
When the DAG has fewer outputs than inputs (e.g., when columns are removed
by an expression), `num_outputs` can be smaller than expected, causing the
loop to exceed `non_mapped` bounds and trigger a SIGABRT in debug builds.

Add `i < non_mapped.size()` as an additional loop bound.

CI failure seen in: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100948&sha=7727d7282d1d05a1fcd6c1f9076aee1f066b96e5&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e018c08]

Summary: ✅


AI Review

Summary

This PR fixes an out-of-bounds read in getRequiredHeaderPositions by bounding iteration with non_mapped.size() in addition to required_output_positions.size(). The fix is precise, matches the failure mode described in the PR, and I did not find additional correctness or safety regressions in the touched logic.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 30, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@clickhouse-gh

clickhouse-gh Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.20% 76.20% +0.00%

Changed lines: 100.00% (4/4) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

@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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Apr 25, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 25, 2026
Merged via the queue into master with commit 1619dd4 Apr 25, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-lazy-materialization-oob branch April 25, 2026 12:52
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 25, 2026
@antaljanosbenjamin antaljanosbenjamin added v25.12-must-backport pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed v25.12-must-backport labels Sep 8, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 8, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 8, 2026
PedroTadim added a commit that referenced this pull request Sep 8, 2026
Backport #101144 to 26.3: Fix out-of-bounds access in getRequiredHeaderPositions for lazy materialization
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
…quiredHeaderPositions for lazy materialization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default 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.

5 participants