Skip to content

Add readBigStrict and use it in buffer deserialization - #107196

Merged
Avogar merged 2 commits into
ClickHouse:masterfrom
Ergus:add_read_check
Jun 12, 2026
Merged

Avogar merged 2 commits into
ClickHouse:masterfrom
Ergus:add_read_check

Conversation

@Ergus

@Ergus Ergus commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

Add a size match check after readBig

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

Version info

  • Merged into: 26.6.1.707

@Ergus
Ergus requested a review from Avogar June 11, 2026 11:49
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2d3ec60]

Summary: ❌

job_name test_name status info comment
Performance Comparison (arm_release, master_head, 1/6) FAIL Performance dashboard
formats_columns_sampling #5::old FAIL query history IGNORED
formats_columns_sampling #5::new FAIL query history IGNORED
functions_coding #0::old FAIL query history IGNORED
functions_coding #0::new FAIL query history IGNORED
uniqExactIf #0::old FAIL query history IGNORED
uniqExactIf #0::new FAIL query history IGNORED
uniqExactIf #1::old FAIL query history IGNORED
uniqExactIf #1::new FAIL query history IGNORED
uniqExactIf #2::old FAIL query history IGNORED
uniqExactIf #2::new FAIL query history IGNORED
2 more test cases not shown

AI Review

Summary

This PR adds ReadBuffer::readBigStrict and uses it in SerializationString::deserializeBinaryBulkWithSizeStream so a truncated String data stream no longer produces a ColumnString whose offsets outlive its chars. The implementation direction is correct, but the PR still lacks focused regression coverage for the exact corrupted-part path it is changing, so I would request changes before merge.

Tests
  • ⚠️ [src/DataTypes/Serializations/SerializationString.cpp:857] The changed contract is that StringSizes and Regular streams must agree and a short readBig now throws through readBigStrict, but no test creates a MergeTree part with string_serialization_version = 'with_size_stream', truncates the String data stream while leaving the size stream intact, and verifies that reading the part fails at this path. Please add that focused regression test so a future refactor cannot silently restore the malformed ColumnString behavior.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: add the focused corrupted with_size_stream String part regression test described above.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 11, 2026
data.resize(initial_size + bytes_to_read);
stream->ignore(bytes_to_skip);
size_t size = stream->readBig(reinterpret_cast<char*>(&data[initial_size]), bytes_to_read);
if (size != bytes_to_read)

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.

This guard is the behavioral contract of the PR, but there is no regression test for it. Please add a focused test that creates a MergeTree part using string_serialization_version = with_size_stream, truncates the String data stream while leaving the size stream intact, and verifies that reading the part fails with this INCORRECT_DATA path instead of returning a malformed ColumnString or surfacing a later LOGICAL_ERROR. Without coverage, the next readBig refactor can silently reintroduce the partial-read behavior this is fixing.

@Avogar Avogar self-assigned this Jun 11, 2026
@Ergus Ergus changed the title Add size check after readBig Add readBigStrict and use it in buffer deserialization Jun 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 17/19 (89.47%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@Avogar
Avogar added this pull request to the merge queue Jun 12, 2026
Merged via the queue into ClickHouse:master with commit dabafca Jun 12, 2026
164 of 166 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 12, 2026
pull Bot pushed a commit to AKJUS/ClickHouse that referenced this pull request Jun 17, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @Ergus @Avogar — a couple of suggestions to make this PR easier for reviewers and the changelog reader.

Description (currently incomplete):

  • Why: The body only restates the title ('Add a size match check after readBig') and does not explain WHY: that the prior code committed full offsets from the .size stream but shrank chars on a short read, yielding an inconsistent ColumnString (offsets.back() > chars.size()) that over-reads during merge.

  • Suggested addition:

    Previously deserializeBinaryBulkWithSizeStream appended offsets for the full per-row sizes from the .size stream, but on a short read of the data stream it shrank chars to the bytes actually read, leaving offsets.back() > chars.size(). That inconsistent column over-reads in ColumnString::insertRangeFrom during a later merge. readBigStrict now fails loudly with CANNOT_READ_ALL_DATA at deserialization instead of producing the corrupt column.

Ignore this if the current title/body is intentional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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