Skip to content

Fix heap-buffer-overflow in leftPad/rightPad functions - #101951

Merged
rschu1ze merged 6 commits into
masterfrom
pad-asan
Apr 8, 2026
Merged

rschu1ze merged 6 commits into
masterfrom
pad-asan

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Apr 7, 2026 •

Copy link
Copy Markdown
Member

Same as #101191 but done in a more clean way.

The relevant commit is 4e6a162, the other commit is cosmetics.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Version info

  • Merged into: 26.4.1.662
  • Backported to: 26.3.5.11, 26.2.9.8

@rschu1ze rschu1ze changed the title Pad asan Fix heap-buffer-overflow in leftPad/rightPad functions Apr 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a2d23c2]

Summary: ⏳

job_name test_name status info comment
Stateless tests (amd_tsan, parallel, 1/2) failure
03753_merge_selector_amm FAIL cidb, issue ISSUE CREATED
Stress test (arm_msan) failure
Server died FAIL cidb, issue ISSUE EXISTS
MemorySanitizer: use-of-uninitialized-value (STID: 4179-5154) FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR fixes an ASan heap-buffer-overflow in leftPad/rightPad by storing padding bytes in PaddedPODArray<UInt8> and extending coverage with dedicated stateless tests. I found no remaining correctness/safety/performance blockers after the follow-up fixes; only one typo in a changed comment was reported inline.

Findings

💡 Nits

  • [src/Functions/padString.cpp:57] Typo in comment text: it's length should be its length.
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 ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 7, 2026
Comment thread src/Functions/padString.cpp Resolved
@nihalzp nihalzp self-assigned this Apr 7, 2026
Comment thread src/Functions/padString.cpp Outdated
"Illegal column {}, first argument of function {} must be a string",
arguments[0].column->getName(),
getName());
chassert(false);

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.

executeImpl used to throw ILLEGAL_COLUMN on an unexpected first-argument column type, but this branch now uses only chassert(false). In release builds, chassert is compiled out, so this path becomes a silent fallthrough returning an incomplete result column instead of a deterministic exception.

Please keep a real runtime exception here (as before) and keep chassert optionally in addition for debug builds.

}

/// Not necessary, but good for performance.
/// We repeat `pad_string` multiple times until it's length becomes 16 or more.

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.

Typo in comment: use its length instead of it's length.

@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.90% 84.00% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.40% 76.50% +0.10%

Changed lines: 93.46% (100/107) | lost baseline coverage: 47 line(s) · Uncovered code

Full report · Diff report

@rschu1ze

rschu1ze commented Apr 8, 2026 •

Copy link
Copy Markdown
Member Author

Stateless tests (amd_tsan, parallel, 1/2) - 03753_merge_selector_amm - #102081

Stress test (arm_msan) - MemorySanitizer: use-of-uninitialized-value (STID: 4179-5154) - #101649

@rschu1ze
rschu1ze added this pull request to the merge queue Apr 8, 2026
@rschu1ze rschu1ze added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Apr 8, 2026
@rschu1ze rschu1ze changed the title Fix heap-buffer-overflow in leftPad/rightPad functions Fix heap-buffer-overflow in leftPad/rightPad functions Apr 8, 2026
Merged via the queue into master with commit cd0e0a0 Apr 8, 2026
155 of 158 checks passed
@rschu1ze
rschu1ze deleted the pad-asan branch April 8, 2026 15:41
robot-clickhouse added a commit that referenced this pull request Apr 8, 2026

@nihalzp nihalzp left a comment

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.

Apart from the issues in the comment, looks good!

{
size_t number_of_arguments = arguments.size();
FunctionArgumentDescriptors mandatory_args{
{"string", static_cast<FunctionArgumentDescriptor::TypeValidator>(&isStringOrFixedString), nullptr, "Array"},

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.

Suggested change
{"string", static_cast<FunctionArgumentDescriptor::TypeValidator>(&isStringOrFixedString), nullptr, "Array"},
{"string", static_cast<FunctionArgumentDescriptor::TypeValidator>(&isStringOrFixedString), nullptr, "String or FixedString"},

{"length", static_cast<FunctionArgumentDescriptor::TypeValidator>(&isInteger), nullptr, "const UInt*"},
};
FunctionArgumentDescriptors optional_args{
{"pad_string", static_cast<FunctionArgumentDescriptor::TypeValidator>(&isString), isColumnConst, "Array"}

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.

Suggested change
{"pad_string", static_cast<FunctionArgumentDescriptor::TypeValidator>(&isString), isColumnConst, "Array"}
{"pad_string", static_cast<FunctionArgumentDescriptor::TypeValidator>(&isString), isColumnConst, "const String"}

@rschu1ze

rschu1ze commented Apr 8, 2026

Copy link
Copy Markdown
Member Author

Sorry @nihalzp - I should have waited for your review. I made a fix that addresses your comments.

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 8, 2026
@nihalzp
nihalzp deleted the pad-asan branch April 8, 2026 16:46
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 8, 2026
clickhouse-gh Bot added a commit that referenced this pull request Apr 8, 2026
Backport #101951 to 26.2: Fix heap-buffer-overflow in `leftPad/rightPad` functions
rschu1ze added a commit that referenced this pull request Apr 8, 2026
Backport #101951 to 26.3: Fix heap-buffer-overflow in `leftPad/rightPad` functions
github-merge-queue Bot pushed a commit that referenced this pull request Apr 8, 2026
`left/rightPad`: Fix argument description (follow-up to #101951)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-approved Approved, but after the PR is merged. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci 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