Skip to content

Text index: fix out-of-bounds write in front-coding deserialization - #114155

Merged
CurtizJ merged 7 commits into
masterfrom
ahmadov/text-index-front-coding-lcp-check
Aug 13, 2026
Merged

CurtizJ merged 7 commits into
masterfrom
ahmadov/text-index-front-coding-lcp-check

Conversation

@ahmadov

@ahmadov ahmadov commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Fixes https://github.com/ClickHouse/clickhouse-private/issues/65753.

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):

Reject corrupted/malicious dictionary where lcp exceeds the previous token or lcp + data_size overflows, before the buffer write.

Version info

  • Merged into: 26.8.1.1320 (included in 26.8 and later)
  • Backported to: 26.7.5.2, 26.5.8.13, 26.3.21.10

…alization

Reject corrupted/malicious dictionary where `lcp` exceeds the previous
token or `lcp + data_size` overflows, before the buffer write.
@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c0721f4]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_tsan, s3 storage, parallel, 1/3) FAIL
04101_variant_adaptor_propagate_exceptions FAIL cidb IGNORED
Bugfix validation (unit tests) ERROR
Compile before-binary (ninja unit_tests_dbms, without the fix) ERROR IGNORED

AI Review

Summary

This PR hardens front-coded text-index dictionary deserialization by rejecting invalid lcp/size combinations before they can wrap the reconstruction buffer, and it mirrors the shared string-size cap on the writer-side token serialization and sparse-index copy paths. I did not find any remaining correctness or safety issues in the current diff. The new gtests cover the corrupted front-coding read-side cases that motivated the fix, and the PR CI report is green; the only residual gap is that the new writer-side oversize-token rejection is not directly unit-tested, which is understandable because constructing a realistic >16_GiB token in a focused unit test is not practical.

Final Verdict

✅ No new review findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.00% +0.00%

Changed lines: Changed C/C++ lines covered: 137/139 (98.56%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 10, 2026
Reject first/reconstructed tokens larger than SerializationString::MAX_STRING_SIZE.

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

LGTM

@CurtizJ CurtizJ self-assigned this Aug 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

No arm_release build profile data for commit c0721f4 - the build was skipped, reused from cache, or predates profile upload.

UInt64 first_token_size = 0;
readVarUInt(first_token_size, istr);
/// Prevent a corrupt or malicious .dct file from allocating huge amounts of memory
if (first_token_size > SerializationString::MAX_STRING_SIZE)

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.

Call checkTokenSize here?

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.

checkTokenSize throws an exception with TOO_LARGE_STRING_SIZE but we need CORRUPTED_DATA here instead.

"Corrupted text index dictionary: front-coding token size overflows (lcp = {}, data_size = {})",
lcp, data_size);

if (token_size > SerializationString::MAX_STRING_SIZE)

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.

.

@CurtizJ
CurtizJ added this pull request to the merge queue Aug 13, 2026
Merged via the queue into master with commit c42c154 Aug 13, 2026
177 of 180 checks passed
@CurtizJ
CurtizJ deleted the ahmadov/text-index-front-coding-lcp-check branch August 13, 2026 11:40
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 13, 2026
@ahmadov ahmadov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 19, 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 Aug 19, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 19, 2026
Backport #114155 to 26.6: Text index: fix out-of-bounds write in front-coding deserialization
robot-ch-test-poll added a commit that referenced this pull request Aug 19, 2026
Cherry pick #114155 to 26.5: Text index: fix out-of-bounds write in front-coding deserialization
robot-clickhouse added a commit that referenced this pull request Aug 19, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Aug 19, 2026
Cherry pick #114155 to 26.3: Text index: fix out-of-bounds write in front-coding deserialization
robot-clickhouse added a commit that referenced this pull request Aug 19, 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 Aug 19, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 19, 2026
Backport #114155 to 26.7: Text index: fix out-of-bounds write in front-coding deserialization
CurtizJ added a commit that referenced this pull request Aug 21, 2026
Backport #114155 to 26.5: Text index: fix out-of-bounds write in front-coding deserialization
CurtizJ added a commit that referenced this pull request Aug 21, 2026
Backport #114155 to 26.3: Text index: fix out-of-bounds write in front-coding deserialization
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.

6 participants