Skip to content

Map wire-controlled checks in SerializationReplicated to INCORRECT_DATA - #114186

Merged
Avogar merged 1 commit into
masterfrom
fix-replicated-serialization-sibling-logical-errors
Aug 13, 2026
Merged

Avogar merged 1 commit into
masterfrom
fix-replicated-serialization-sibling-logical-errors

Conversation

@Avogar

@Avogar Avogar commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Closes: #113997
Related: #112331

SerializationReplicated::deserializeBinaryBulkWithMultipleStreams had three sibling checks that still threw LOGICAL_ERROR for conditions decided purely by untrusted native-protocol bytes:

  • a non-empty target column, reachable via a Sparse-over-Replicated kind stack (a fresh ColumnSparse always seeds one default value, which is then handed to the nested Replicated deserialization);
  • an index row count that disagrees with the block row count;
  • an unsupported index-type width.

In debug and sanitizer builds LOGICAL_ERROR is routed to abortOnFailedAssertion, so a crafted block sent by any authenticated client aborts the server; in release builds it is the wrong error class and trips CI checks that scan logs for Logical error.

This changes all three to INCORRECT_DATA, matching the checks added in #112331 and the analogous SerializationLowCardinality code. The native-protocol regression test 04616_replicated_serialization_oob_index_native_protocol is extended with the three scenarios (invalid index type width, index row count mismatch, Sparse-over-Replicated), each asserting error code 117 and that the server stays alive. Verified against a Debug build.

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

Fixed the error code reported for some malformed Replicated-serialized columns received over the Native protocol: these are now rejected with INCORRECT_DATA instead of LOGICAL_ERROR (which aborted the server in debug and sanitizer builds).

Version info

  • Merged into: 26.8.1.1364 (included in 26.8 and later)

`SerializationReplicated::deserializeBinaryBulkWithMultipleStreams` had three
sibling checks that still threw `LOGICAL_ERROR` for conditions decided purely by
untrusted native-protocol bytes:

- a non-empty target column, reachable via a `Sparse`-over-`Replicated` kind
  stack (a fresh `ColumnSparse` always seeds one default value, which is then
  handed to the nested `Replicated` deserialization);
- an index row count that disagrees with the block row count;
- an unsupported index-type width.

In debug and sanitizer builds `LOGICAL_ERROR` is routed to
`abortOnFailedAssertion`, so a crafted block aborts the server; in release builds
it is the wrong error class and trips CI checks that scan logs for `Logical error`.

Change all three to `INCORRECT_DATA`, matching the checks added in #112331 and the
analogous `SerializationLowCardinality` code, and extend the native-protocol
regression test with the three scenarios.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b3cddfb]

Summary: ❌

job_name test_name status info comment
Stress test (amd_asan_ubsan) FAIL
Sanitizer (STID: 2064-22d0) FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR reclassifies three wire-controlled SerializationReplicated Native-deserialization failures from LOGICAL_ERROR to INCORRECT_DATA and extends the native-protocol regression test to cover them. I did not find any correctness, coverage, or PR-metadata issues in the current diff.

Final Verdict

✅ No blocking issues found.

LLVM Coverage Report

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

Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · 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

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

Pretty simple change. LGTM

@Avogar
Avogar added this pull request to the merge queue Aug 13, 2026
Merged via the queue into master with commit bf580ec Aug 13, 2026
179 of 181 checks passed
@Avogar
Avogar deleted the fix-replicated-serialization-sibling-logical-errors branch August 13, 2026 19:45
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 13, 2026
vdimir added a commit that referenced this pull request Nov 18, 2026
The change is taken as in the original (1a44640, #130895), with the adaptations below.

Adapted:
- `src/Formats/NativeReader.h`, `src/Formats/NativeReader.cpp`: the new `allowed_kinds_` parameter and the
  `allowed_kinds(allowed_kinds_)` initializer go after `block_missing_values_`, without the master-only
  `type_cache_` (`NativeReaderTypeCache`, #129831). The branch keeps its own
  `format_settings_ = std::nullopt` default.
- `src/Processors/Formats/Impl/NativeFormat.cpp` (`makeReader`): the `/*type_cache_=*/ nullptr,` argument is
  dropped. The file merged without a conflict, but would not compile as merged.
- `src/Server/TCPHandler.cpp`: the original only adds the `ISerialization::KindSet{ISerialization::Kind::DEFAULT}`
  argument; `getNativeWireFormatSettings` (#123649) is on its context lines and is not on the branch.
  `skipDataPacket` passes no format settings here, so an explicit `std::nullopt` stands in that position.
  `initBlockInput` keeps `getFormatSettings(state.query_context)`, with an explicit `nullptr` for
  `block_missing_values_` and without `type_cache_`. Both comments of the original are kept.
- `src/Interpreters/AsynchronousInsertQueue.cpp`: `IColumn::convertToFullIfWrapped` (#107773) is not on the
  branch, and `convertToFullIfNeeded` also strips `LowCardinality`. The check uses a file-local
  `hasWrappedColumn` instead: a `ColumnBLOB`, `ColumnConst`, `ColumnReplicated` or `ColumnSparse` at any
  nesting depth, `LowCardinality` left alone, nothing converted. The exception and its message are as in the
  original. The only producers of `pushQueryWithBlock` on the branch are the two calls in
  `TCPHandler::processAsyncInsertQuery`: a header without columns, and the squashed blocks that
  `initBlockInput` reads, which now accepts only the default kind.

Left out:
- `tests/queries/0_stateless/04616_replicated_serialization_oob_index_native_protocol.python` and `.reference`:
  the scenarios the branch does not have: invalid index type size, index row count mismatch, sparse over
  replicated (#114186) and huge element count (#129932). The rewrite of the two existing scenarios and the new
  `replicatedTupleElementScenario` and `replicatedOnInsertScenario` are kept, with their reference lines.
- `tests/queries/0_stateless/05473_sparse_truncated_values_native_protocol.python`, `.reference`, `.sh`: the
  original only edits this test, and it comes from #128363, which is not on the branch (modify/delete
  conflict).
- `docs/resources/develop-contribute/native-protocol/format.mdx`: the branch has no English specification of
  the `Native` format, so the hunks have nowhere to go (modify/delete conflict).

`tests/queries/0_stateless/helpers/fake_native_server.py` is as in the original here. It does not work with
the client of this branch, which sends a `Ping` before each query; the next commit adapts it.

Everything else merged without conflicts and has the same changed lines as the original.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

3 participants