Repository navigation
Reject truncated sparse values in native protocol input with INCORRECT_DATA - #128363
Conversation
A TCP client chooses the serialization kind of the INSERT data it sends (NativeReader, client protocol revision >= 54454). For a SPARSE column whose values payload is shorter than its offsets declare, primitive bulk readers such as SerializationNumber::deserializeBinaryBulk short-read on EOF without throwing, so the values/offsets size check in SerializationSparse::deserializeBinaryBulkWithMultipleStreams is the first to see the mismatch. It always threw LOGICAL_ERROR, which aborts debug and sanitizer servers (found by native_reader_fuzzer in the nightly libFuzzer run). Throw INCORRECT_DATA when settings.native_format is set, like the sibling checks in SerializationTuple, SerializationNullable, SerializationObject, SerializationVariant and SerializationReplicated. Other readers keep LOGICAL_ERROR, where the check catches internal bugs. ClickHouse#102975 added this ternary and reverted it for lack of a reachable test; the new test 05473_sparse_truncated_values_native_protocol reaches it from a raw native-protocol client. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261031-105700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261031-102900 |
|
cc @Avogar @antaljanosbenjamin, could you review this and add the |
|
Workflow [PR], commit [a608265] Summary: ✅
AI ReviewSummaryThe change makes Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 7 s compile time in total, 8 of them have a recent master baseline. |
defab2b
The change is taken as in the original (1a44640, #130895); only the following is 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_`. The master-only `type_cache_` parameter and initializer are not added: `NativeReaderTypeCache` (#129831) is not on the branch, and the change does not use it. The branch keeps its own `format_settings_ = std::nullopt` default. - `src/Processors/Formats/Impl/NativeFormat.cpp` (`makeReader`) and `src/Server/TCPHandler.cpp` (`initBlockInput`): the `/*type_cache_=*/ nullptr,` argument is dropped, because the constructor on the branch has no such parameter. These two files merged without a conflict, but would not compile as merged. - `tests/queries/0_stateless/04616_replicated_serialization_oob_index_native_protocol.python` and `.reference`: the huge-element-count scenario (`replicatedBlockWithHugeElementCount`, `hugeElementCountScenario`, its call in `main`, its reference line) is left out. It comes from #129932, which is not on the branch: the test there never had the scenario or the `expectException` helper, and `SerializationReplicated` has no 'Suspiciously many elements' check. The new `replicatedTupleElementScenario` and `replicatedOnInsertScenario` are kept, with their reference lines. - `tests/queries/0_stateless/05473_sparse_truncated_values_native_protocol.python`, `.reference`, `.sh`: left out. The original only edits this test, and it comes from #128363, which is not on the branch (modify/delete conflict). - `docs/reference/interfaces/specs/NativeFormat.mdx`: git applied the hunks of `docs/resources/develop-contribute/native-protocol/format.mdx` here, where the same document lives on the branch. The added and removed lines are the same as in the original. Everything else merged without conflicts and has the same changed lines as the original. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The change is taken as in the original (1a44640, #130895); only the following is 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_`. The master-only `type_cache_` parameter and initializer are not added: `NativeReaderTypeCache` (#129831) is not on the branch, and the change does not use it. The branch keeps its own `format_settings_ = std::nullopt` default. - `src/Processors/Formats/Impl/NativeFormat.cpp` (`makeReader`) and `src/Server/TCPHandler.cpp` (`initBlockInput`): the `/*type_cache_=*/ nullptr,` argument is dropped, because the constructor on the branch has no such parameter. These two files merged without a conflict, but would not compile as merged. - `tests/queries/0_stateless/04616_replicated_serialization_oob_index_native_protocol.python` and `.reference`: the huge-element-count scenario (`replicatedBlockWithHugeElementCount`, `hugeElementCountScenario`, its call in `main`, its reference line) is left out. It comes from #129932, which is not on the branch: the test there never had the scenario or the `expectException` helper, and `SerializationReplicated` has no 'Suspiciously many elements' check. The new `replicatedTupleElementScenario` and `replicatedOnInsertScenario` are kept, with their reference lines. - `tests/queries/0_stateless/05473_sparse_truncated_values_native_protocol.python`, `.reference`, `.sh`: left out. The original only edits this test, and it comes from #128363, which is not on the branch (modify/delete conflict). Everything else merged without conflicts and has the same changed lines as the original. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The change is taken as in the original (1a44640, #130895); only the following is 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_`. The master-only `type_cache_` parameter and initializer are not added: `NativeReaderTypeCache` (#129831) is not on the branch, and the change does not use it. The branch keeps its own `format_settings_ = std::nullopt` default. - `src/Processors/Formats/Impl/NativeFormat.cpp` (`makeReader`) and `src/Server/TCPHandler.cpp` (`initBlockInput`): the `/*type_cache_=*/ nullptr,` argument is dropped, because the constructor on the branch has no such parameter. These two files merged without a conflict, but would not compile as merged. - `tests/queries/0_stateless/04616_replicated_serialization_oob_index_native_protocol.python` and `.reference`: the huge-element-count scenario (`replicatedBlockWithHugeElementCount`, `hugeElementCountScenario`, its call in `main`, its reference line) is left out. It comes from #129932, which is not on the branch: the test there never had the scenario or the `expectException` helper, and `SerializationReplicated` has no 'Suspiciously many elements' check. The new `replicatedTupleElementScenario` and `replicatedOnInsertScenario` are kept, with their reference lines. - `tests/queries/0_stateless/05473_sparse_truncated_values_native_protocol.python`, `.reference`, `.sh`: left out. The original only edits this test, and it comes from #128363, which is not on the branch (modify/delete conflict). - `docs/reference/interfaces/specs/NativeFormat.mdx`: git applied the hunks of `docs/resources/develop-contribute/native-protocol/format.mdx` here, where the same document lives on the branch. The added and removed lines are the same as in the original. Everything else merged without conflicts and has the same changed lines as the original. Co-Authored-By: Claude Fable 5.2 <[email protected]>
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]>
Related: #102975
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A sparse column whose values are truncated in data sent over the native protocol is now rejected with
INCORRECT_DATAinstead ofLOGICAL_ERROR.Description
native_reader_fuzzeraborted in the nightlylibFuzzer testsrun (report) at the values/offsets size check ofSerializationSparse::deserializeBinaryBulkWithMultipleStreams, which always throwsLOGICAL_ERROR.The same check is reachable from any TCP client:
TCPHandler::initBlockInputreads INSERT data withNativeReaderat the client's protocol revision, so the client chooses theSPARSEkind. If the values payload is shorter than the offsets declare,SerializationNumber::deserializeBinaryBulkshort-reads on EOF without throwing, and the Sparse check is the first to see the mismatch. A debug or sanitizer server aborts; a release server answersLOGICAL_ERROR.The check now throws
INCORRECT_DATAwhensettings.native_formatis set, asSerializationTuple,SerializationNullable,SerializationObject,SerializationVariantand the truncated-elements check ofSerializationReplicatedalready do. Other readers (MergeTree and others) keepLOGICAL_ERROR, where this check catches real internal bugs.#102975 added this ternary and reverted it because no test could reach the site from input data. The new test
05473_sparse_truncated_values_native_protocolreaches it from a raw native-protocol client (the offsets declare 2 values, 1 is sent) and expects code 117 with the server alive.Validation: on a master debug build the test aborts the server with
Offsets size: 2, values size: 2; with the fix it passes 50/50 randomized runs. Replaying the exact 183-byte fuzzer input over TCP aborts master withOffsets size: 66, values size: 5and returns code 117 with the fix.Workflow [PR]
Sync PR [sync-upstream/pr/128363]
Version info
26.11.1.976-master(included in26.11and later)