Skip to content

Add support for native compression with external tables via HTTP - #93462

Open
maxjustus wants to merge 62 commits into
ClickHouse:masterfrom
maxjustus:http_external_table_compression
Open

maxjustus wants to merge 62 commits into
ClickHouse:masterfrom
maxjustus:http_external_table_compression

Conversation

@maxjustus

@maxjustus maxjustus commented Jan 6, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

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

Add support for native compression with external tables via HTTP.

Documentation entry for user-facing changes

  • [x ] Documentation is written (mandatory for new features)

Workflow [PR]
Sync PR [sync-upstream/pr/93462]

@maxjustus maxjustus changed the title feat: add support for native compression with external tables via HTTP Add support for native compression with external tables via HTTP Jan 6, 2026
@GrigoryPervakov GrigoryPervakov added the can be tested Allows running workflows for external contributors label Jan 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jan 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3a82c00]

Summary: ❌

job_name test_name status info comment
Build (arm_tidy, 1/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 2/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 3/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 4/4) FAIL
Build ClickHouse FAIL cidb
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED

AI Review

⚠️ Review sessions stopped as a cybersecurity risk

The model provider stopped these review sessions as a possible cybersecurity risk:

  • attempt 1: gpt-6.1-sol

This summary comes from a session with gpt-5.4. A session is typically stopped when it reaches a memory-safety finding, and the finding is lost with it, so this review can miss a real defect. Please review the change in detail, and run the review internally with a model that has cyber access.

Summary

This PR adds native-compressed external-table uploads over HTTP and hardens multipart/body parsing limits around them. I found one remaining regression in the HTTP parameter filtering: multipart requests with external tables now silently drop legitimate handler/query parameters whose names end with _decompress or _disable_checksum, so I can’t approve it yet.

Findings
  • ⚠️ Majors
    • [src/Server/HTTPHandler.cpp:388] The new suffix-based skip runs before customizeQueryParam, so any param_*, declared handler parameter, or custom query_param_name ending with _decompress / _disable_checksum is discarded whenever has_external_data is true. That breaks unrelated handlers/queries with missing parameter / query not found failures. Suggested fix: let handler/query-parameter binding run before the external-table metadata skip, or restrict the skip to otherwise-unrecognized names only, and add a focused regression for one affected parameter name.
Final Verdict

Status: ⚠️ Request changes

  • Preserve legitimate handler/query parameters whose names happen to end with _decompress or _disable_checksum when has_external_data is true, while still skipping the actual external-table metadata fields.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jan 6, 2026
@maxjustus
maxjustus force-pushed the http_external_table_compression branch 2 times, most recently from c5600d7 to e87dbf1 Compare January 6, 2026 18:33
@maxjustus

Copy link
Copy Markdown
Contributor Author

failures appear unrelated, this should be good to go!

@alexey-milovidov

Copy link
Copy Markdown
Member

@maxjustus, it requires documentation for new features:

python3 ./ci/jobs/scripts/workflow_hooks/feature_docs.py

maxjustus and others added 2 commits March 16, 2026 20:03
- Rebase the original commit onto current master
- Add documentation for `_decompress` and `_disable_checksum` parameters
  to satisfy the feature_docs CI check
- Rename test from 03756 to 04040 (next available number)
- Remove unnecessary `no-parallel` tag from test

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov force-pushed the http_external_table_compression branch from e87dbf1 to ab29e24 Compare March 16, 2026 20:06
@maxjustus

Copy link
Copy Markdown
Contributor Author

oh cool, looks like you took care of that. I think the CI fails are still unrelated

…le_compression

* upstream/master: (6651 commits)
  Update version_date.tsv and changelogs after v25.12.10.7-stable
  tests: correct `long` tag comment on 01114_database_atomic
  Harden lexer and UTF-8 subsequence for fuzzer sanitizers
  add guard to getURLScheme - found by unit test
  Fix flaky test 02818_memory_profiler_sample_min_max_allocation_size on amd_llvm_coverage
  tests: mark 01114_database_atomic as long to avoid flaky-check 180s cap
  better test
  Squashed commit of the following:
  Add regression test for SIGSEGV in full_sorting_merge LEFT JOIN with JSON columns
  Pack hot `MemoryTracker` fields into a single cache line
  Avoid false sharing in `MemoryTracker` via cache-line field grouping
  Update comment for MemoryTracker
  impl
  CI: print stack trace on `ServerDied` exception
  Retrigger CI after DNS infrastructure flake (no code change)
  Removed test
  CI: move macOS fast test skip list to `ci/defs/darwin.skip` and add more tests
  Fix flaky test 03008_uniq_exact_equal_ranges under MSan/WasmEdge
  Fix flaky test 01872_functions_to_subcolumns_analyzer
  Fix BSONEachRow rollback crash on malformed nullable array elements
  ...
Comment thread src/Core/ExternalTable.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

Ok, now it is almost perfect. There is one pending, reasonable suggestion from the reviewer.

maxjustus and others added 4 commits April 26, 2026 07:49
04040 and 04114 collided with tests added on master; renumber to
04310 and 04311.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…abase

The test created a fixed global user `test_decompress_limit_user`. Because
ClickHouse users are server-global, running the test concurrently (as the
flaky check does) caused `ACCESS_ENTITY_ALREADY_EXISTS` on `CREATE USER` and
`UNKNOWN_USER` on `DROP USER`. Scope the user name to `CLICKHOUSE_DATABASE` so
parallel runs do not collide.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Picked this up to move it forward:

  • Merged master into the branch (it was ~9.5k commits / over a month behind). No code conflicts; resynced the rust_vendor submodule which the merge bumped.
  • Resolved the reviewer's decompression-bomb concern (src/Core/ExternalTable.cpp). The fix was already implemented in a5ea06a8c1f: when <name>_decompress is set, the CompressedReadBuffer is wrapped in a LimitReadBuffer bounded by http_max_multipart_form_data_size, so the limit now applies to the decompressed byte count. I replied to and resolved that thread.
  • Renumbered the two new tests to avoid collisions introduced by master: 04040→04310_http_external_table_native_compressed, 04114→04311_http_external_table_decompression_limit.
  • Fixed the flaky-check failure on 04311: the test created a fixed global user test_decompress_limit_user. Since ClickHouse users are server-global, concurrent runs in the flaky check collided with ACCESS_ENTITY_ALREADY_EXISTS / UNKNOWN_USER. The user name is now scoped to ${CLICKHOUSE_DATABASE}.

Verified locally on a freshly built binary — both 04310 and 04311 pass.

Remaining red CI before the merge was unrelated to this change:

  • Stress test (arm_debug): Logical error: Port is already connected (STID 0996-3f42) — query-pipeline error unrelated to external-table compression.
  • Upgrade check (amd_release): Unknown tokenizer: 'unicode_word' while attaching a text index — a text-index upgrade-compat issue, unrelated.

These should be re-evaluated after CI re-runs on the merged branch; CH Inc sync should also re-run.

alexey-milovidov and others added 2 commits June 6, 2026 11:33
…HTTP data

The reviewer noted that wrapping the `CompressedReadBuffer` in a
`LimitReadBuffer` bounded by `http_max_multipart_form_data_size` is too late
to stop a decompression bomb: `CompressedReadBuffer::nextImpl` reads
`size_decompressed` from the (untrusted) block header and calls
`memory.resize(size_decompressed + ...)` before the outer limit can cap the
read. Only `size_compressed_without_checksum` was bounded (against
`DBMS_MAX_COMPRESSED_SIZE`), so a tiny crafted block declaring a huge
decompressed size could still force an oversized allocation.

Add an optional per-block decompressed-size limit to
`CompressedReadBufferBase` (`setDecompressedSizeLimit`, default disabled). When
set, `readCompressedData` rejects a block whose declared decompressed size
exceeds the limit with `TOO_LARGE_SIZE_COMPRESSED`, before any decompressed
buffer is allocated. `ExternalTable` now sets this limit to
`http_max_multipart_form_data_size` on the external-data path, while keeping the
outer `LimitReadBuffer` as the total-stream guard.

Tests (renumbered to avoid collisions with new master tests):
- `04322_http_external_table_native_compressed`
- `04323_http_external_table_decompression_limit` now exercises the cumulative
  total-limit path (blocks individually under the limit, total over it ->
  `CANNOT_READ_ALL_DATA`).
- `04324_http_external_table_decompression_bomb` (new) crafts a single block
  whose declared decompressed size exceeds the limit and asserts it is rejected
  with `TOO_LARGE_SIZE_COMPRESSED` before allocation.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Continued moving this forward:

  • Merged master into the branch (it was ~720 commits behind and red). Clean merge; resynced the mariadb-connector-c submodule that the merge bumped.
  • Fully addressed the reviewer's remaining decompression-bomb concern (82c2f67c0d8). The previous fix wrapped the CompressedReadBuffer in a LimitReadBuffer, but as the reviewer pointed out that is too late: CompressedReadBuffer::nextImpl reads size_decompressed from the (untrusted) block header and does memory.resize(size_decompressed + ...) before the outer limit can cap reads, and only size_compressed_without_checksum was bounded. I added an optional per-block decompressed-size limit to CompressedReadBufferBase (setDecompressedSizeLimit, default disabled) that is checked in readCompressedData right after the header is parsed and before any decompressed allocation; an oversized block is rejected with TOO_LARGE_SIZE_COMPRESSED. ExternalTable sets this limit to http_max_multipart_form_data_size on the _decompress path, keeping the outer LimitReadBuffer as the total-stream guard.
  • Renumbered the tests to avoid collisions with new master tests: 04310→04322, 04311→04323. 04323 now exercises the cumulative total-limit path (blocks individually under the limit, total over it → CANNOT_READ_ALL_DATA).
  • Added a focused regression 04324_http_external_table_decompression_bomb: a single native-compressed block whose declared decompressed size (~1 MB) exceeds a small http_max_multipart_form_data_size, asserting rejection with TOO_LARGE_SIZE_COMPRESSED before allocation.

Verified locally on a freshly built binary — 04322, 04323, and 04324 all pass.

The remaining red CI is unrelated to this change: AST fuzzer (amd_debug) hit Logical error: Duplicate announcement received for replica number (STID 8765-864b), which is thrown in ParallelReplicasReadingCoordinator.cpp — parallel-replicas coordination, not touched by this PR (it only changes HTTP external-table compression). The fuzzer happened to generate a query that triggers that pre-existing coordination bug.

@groeneai, please investigate the unrelated AST fuzzer (amd_debug) failure: Logical error: Duplicate announcement received for replica number (ParallelReplicasReadingCoordinator.cpp, STID 8765-864b) and provide a fix in a separate PR. If a fix is already in progress, please link it here.

Comment thread src/Core/ExternalTable.cpp Resolved
@groeneai

groeneai commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

@ alexey-milovidov picked up the directive to investigate STID 8765-864b (Duplicate announcement received for replica number in ParallelReplicasReadingCoordinator.cpp:222).

CIDB confirms it is unrelated to this PR: the STID is fresh (single hit on this PR's AST fuzzer (amd_debug) run on 2026-06-04 01:10 UTC), zero master hits, zero hits on any other PR in the last 30 days, no existing GitHub issue, no open fix PR. The trigger is a fuzzer-mutated query that exercises parallel replicas inside viewExplain('EXPLAIN PIPELINE', ..., (... EXCEPT DISTINCT ...)) against MergeTree tables — a path completely orthogonal to the ExternalTable / CompressedReadBufferBase changes here.

Investigating in a separate branch; will open the fix PR shortly and link it back here. Session: cron:clickhouse-ci-task-worker:20260606-121600.

@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@ alexey-milovidov status update on STID 8765-864b.

CIDB: still 1 hit in the last 30 days, the original one on this PR's AST fuzzer (amd_debug) run on 2026-06-04 01:10 UTC (sha 49d8248c). Zero on master, zero on any other PR, no recurrence in the 4 days since.

GitHub: searched for Duplicate announcement received for replica, is_announcement_received, 8765-864b, viewExplain parallel replicas. No related open issue, no open fix PR. The only prior fix in this area is @ devcrafter's PR #69146 (merged 2024-09-04, an older variant).

Code path: the assertion at ParallelReplicasReadingCoordinator.cpp:222 is keyed by (stream_id, replica_num), where stream_id is data.getStorageID().getFullTableName() set in ReadFromMergeTree::readFromPoolParallelReplicas via ParallelReadingExtension. For the local replica (replica_num=0), the same stream_id appearing twice in one coordinator's lifetime triggers the duplicate.

The fuzzer-mutated trigger was an outer SELECT ... EXCEPT DISTINCT ... over two viewExplain('EXPLAIN PIPELINE', ...) table functions, with t_row_policy_limit__fuzz_11 referenced inside both viewExplain argument subqueries. The stack runs through evaluateScalarSubqueryIfNeeded -> QueryPlan::buildQueryPipeline -> ReadFromMergeTree::initializePipeline during resolveTableFunction, i.e. while resolving table-function arguments.

Reading evaluateScalarSubqueryIfNeeded (src/Analyzer/Resolve/evaluateScalarSubqueryIfNeeded.cpp:127-141): the scalar subquery's subquery_context correctly sets allow_experimental_parallel_reading_from_replicas = 0, but the cloned query tree only has its immediate QueryNode/UnionNode context overridden. Nested QueryNodes inside the scalar subquery still carry their original per-node contexts with parallel replicas enabled. By contrast, createLocalPlanForParallelReplicas (src/Processors/QueryPlan/ParallelReplicasLocalPlan.cpp:127-156) walks the whole query tree and updates every QueryNode/UnionNode context. The same per-node-context exposure exists in Planner::collectFiltersForAnalysis (src/Planner/Planner.cpp:255-268).

That asymmetry is the most plausible mechanism: a scalar subquery evaluated under resolveTableFunction for a query whose outer level is also parallel-replicas can land a second initial announcement against the same coordinator with the same (stream_id, replica_num=0). This is a hypothesis from code reading, however; I have not been able to deterministically reproduce it from the fuzzer's mutated query in a local debug build, and per the team's guidance I am not opening a speculative defensive fix without a concrete reproducer.

Status: monitoring CIDB for any recurrence. If a second hit lands, I will reopen with the new artifact (ideally a debug fatal.log/server.log/coredump from clickhouse-builds) and either pin down the path or open a focused regression-only PR.

Any additional context (fuzzer artifacts still around, prior duplicate-announcement family, expected occasional outcome of the new stream_id-keyed coordinator under aggressive fuzzing) would help narrow this down.

Session: cron:clickhouse-ci-task-worker:20260608-000500.

@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@ alexey-milovidov second update on STID 8765-864b.

Reproduction attempt (master HEAD 38129a8, debug build):

I tried to reproduce the duplicate-announcement crash from the fuzzer's "Failed query" (SELECT * FROM (... viewExplain('EXPLAIN PIPELINE', '', materialize(''), (...)) EXCEPT DISTINCT ...)) under several settings configurations:

  • allow_experimental_parallel_reading_from_replicas 1 / 2
  • parallel_replicas_local_plan = 1, parallel_replicas_for_non_replicated_merge_tree = 1
  • with and without serialize_query_plan = 1
  • with and without nested SETTINGS max_threads = 255, additional_table_filters = ...

The fuzzer's printed query as-is is rejected at parse time: Table function 'viewExplain' requires 2 or 3 arguments, got 4 — viewExplain is a 2-or-3 argument table function (getName, settings_string, [subquery]), and the fuzzer's mutation made it a 4-arg call ('EXPLAIN PIPELINE', '', materialize(''), (subquery)). The same restriction is in place at the failing SHA 49d8248c. The variants without the spurious materialize('') arg run cleanly to a plain EXPLAIN PIPELINE result with no crash.

This strongly suggests the printed "Failed query" is not the mutation that actually caused the crash — it is just the last query the fuzzer attempted. The AST fuzzer reuses the server across many mutated queries; the duplicate-announcement state was almost certainly produced by an earlier mutation that left the parallel-replicas coordinator in a bad state, and the printed query is what was running when the crash surfaced.

Code state on current master (relevant to the hypothesized asymmetry I posted earlier):

  • createLocalPlanForParallelReplicas (src/Processors/QueryPlan/ParallelReplicasLocalPlan.cpp:185-218) DOES recursively walk the cloned query tree and override allow_experimental_parallel_reading_from_replicas = 0 on every QueryNode and UnionNode context. So the asymmetry I suspected in evaluateScalarSubqueryIfNeeded (which only overrides the immediate cloned node's context, not the nested ones — src/Analyzer/Resolve/evaluateScalarSubqueryIfNeeded.cpp:140-145) is real, but it does NOT manifest as a duplicate announcement on master because the local-plan path already neutralizes nested contexts before any ReadFromMergeTree step is built.
  • findReadingStepsUnderUnion was made fully recursive in PR #103xxx (commit 362d0d5a9fa, Apr 2026) — also relevant to nested-view coordination.
  • The check at src/Planner/Planner.cpp:2197-2208 rejects additional_table_filters with parallel replicas (mode 2) without serialize_query_plan = 1. This was live at the failing SHA.

Conclusion: the printed query alone is not a deterministic reproducer; without the fuzzer's preceding-query history or a server core, I cannot pin down which mutation actually leaked a duplicate announcement into the coordinator. CIDB still shows 1 hit in 30 days, no master / cross-PR recurrence in the 4 days since.

I am going to stand down on a speculative fix per @ Algunenano / @ Avogar guidance ("avoid making code changes that you can back with test, queries or reports"). I'll keep CIDB monitoring on the STID and reopen if a second hit lands — ideally with the fatal.log / server.log / coredump from the AST-fuzzer artifact directory so we can identify the actual crash-triggering mutation.

If the fuzzer artifacts (server.log, fatal.log, core) for sha 49d8248c on this PR are still around, that would let me pin this down. Otherwise, monitoring.

Session: cron:clickhouse-ci-task-worker:20260608-051225.

Comment thread src/Core/ExternalTable.cpp Resolved
alexey-milovidov and others added 5 commits October 4, 2026 09:06
# Conflicts:
#	src/Core/Settings.cpp
…uest_header_size`

A content line starting with "\r\n--<boundary>" terminates the part, so it is request
syntax rather than content. Previously the structural limit was checked for it only after
the line had outgrown the content limit, so with a large `http_max_multipart_form_data_size`
such a line with a long tail could be buffered far beyond the user's
`http_max_request_header_size`. Now it is checked as soon as the line outgrows the
structural limit.

Also fix the first line of a part's content being bounded by `http_max_request_header_size`
instead of the content limit: `readHeaders` peeks past the empty line that ends the headers,
so `MultipartReadBuffer` buffered that line before `readMultipart` switched it to content
mode, and a valid first content line longer than the user's header size limit was rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tipart budget

`http_max_multipart_form_data_size` is a budget shared by all parts of the request, but
each native-compressed (`_decompress`) part got the whole limit for its decompressed size,
so several small compressed parts could materialize more external data than the limit.
Limit each part by what is left of the budget after the previous parts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…arts too

The form field name of a part with `filename` (an external table) was passed to
`PartHandler::handlePart` without the length check, so it could exceed the
authenticated user's `http_max_field_name_size`. Check it before the `filename` split.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Server/HTTP/HTMLForm.cpp Resolved
alexey-milovidov and others added 2 commits October 20, 2026 01:15
…t content limit

Once a buffered content line matched the full `\r\n--<boundary>` prefix, any suffix
was accepted up to `http_max_request_header_size` and then discarded as a boundary line,
so bytes could be smuggled past `http_max_multipart_form_data_size`. Past the boundary,
accept only the `--` of the close delimiter and linear whitespace (RFC 2046).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Continued this PR:

  • Review thread (boundary-line suffix bypass of http_max_multipart_form_data_size): fixed in e1b1c9b5c24. Past the content limit, a buffered line may continue after \r\n--<boundary> only with the -- of the close delimiter followed by linear whitespace. Any other byte throws LIMIT_EXCEEDED. New test: 05366_http_external_table_multipart_boundary_suffix.
  • Merged master (69b8ac7f236). The merge was clean and the server builds. The new test and the PR's other multipart/external-table tests (04322, 04326-04330, 04343, 04614, 05218, 05321, 05322) pass locally.
  • CI: the only failure was 05325_iceberg_mixed_format_top_k_dynamic_filtering in Stateless tests (amd_debug, parallel). All reruns passed. The test hit an Iceberg metadata commit race logged at Error level, which this PR does not touch. Related: Log a lost Iceberg metadata commit race at Debug, not Error #125026

Comment thread src/Server/HTTPHandler.cpp Resolved
# Conflicts:
#	src/Compression/CompressedReadBufferBase.h
@mintlify

mintlify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 3a82c00.

Approve preview

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/93462/69b8ac7f23627a56d220701b8a6ecbba47c7cafb/pr/unit_tests_asan_ubsan_function_prop_fuzzer/unit_tests_asan_ubsan_function_prop_fuzzer.log (FunctionsStress.stress in Unit tests (asan_ubsan, function_prop_fuzzer): a thread got stuck re-executing SELECT range(materialize(CAST(2305866 AS UInt32))), unrelated to this PR's HTTP changes) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Fixed by my #126210, merged 2026-10-20 at 13:10 UTC. This run predates it: the workflow for 69b8ac7f started at 02:10 UTC that day, and the stuck worker has the stack that PR addresses (range(materialize(CAST(2305866 AS UInt32))) in __asan_stack_malloc_1 under ColumnVector<unsigned int>::doCompareAt <- ColumnArray::compareAtImpl).

Since the merge, master-based runs of this job have 3 failures out of 2483 (0 of 250 on master), all from workflows created before the merge. The current head 4bb73afa already contains the fix.

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (f5f9111f0bd). The branch was 3260 commits behind and red. The merge was clean and the PR diff did not change (same 44 files). The server builds, and all 18 of the PR's multipart/external-table tests pass locally against the merged binary.

CI on the previous head (4bb73afa):

  • Stress test (amd_debug): Received signal 6 (internal) (STID 1202-2b88). The abort is in DB::highlight (ClientBaseHelpers.cpp), called from ClientBase::echoQuery in the embedded client. That is query highlighting in the client, which this PR does not touch. Fix out-of-bounds write in query highlighting on malformed UTF-8 #127906 ("Fix out-of-bounds write in query highlighting on malformed UTF-8", merged 2026-10-29) changed that code, and this merge pulls it in.
  • Build profile diff: infrastructure failure (LogClusterNotReady: the endpoint never became ready), not related to this PR.

@groeneai, thanks for confirming the FunctionsStress.stress fix (#126210) is already on this branch.

There are no unresolved review threads.

alexey-milovidov and others added 2 commits November 13, 2026 07:53
…arts

- `CompressedReadBufferBase`: add `setCompressedSizeLimit`, which bounds the
  cumulative declared compressed size (including checksums) before a buffer
  for the block is allocated. `ExternalTablesHandler` sets it to the remaining
  `http_max_multipart_form_data_size` budget, so a header-only block declaring
  a huge compressed size is rejected up front instead of forcing a large
  allocation before `readStrict` notices the truncated input.
- `HTMLForm::MultipartReadBuffer::skipToNextBoundary`: initialize the part
  state (`first_line_of_part`, `found_last_boundary`) before `next` reads ahead
  the first line of the part. Otherwise the flag was consumed by the second
  header line, which was then taken for content and rejected by the content
  size limit.

Both cases are covered by a new test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Server/HTTP/HTMLForm.cpp Resolved
alexey-milovidov and others added 2 commits November 20, 2026 22:52
…_compression

Conflict in `src/Core/Settings.cpp`: the descriptions of `http_max_fields`, `http_max_field_name_size` and `http_max_field_value_size` were changed on both sides. Kept the text of this PR (query string is bounded by the server default before authentication) and appended the paragraph from `master` about the headers of HTTP responses read as a client.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ry recognizers

The RFC 2046 check of what may follow the boundary on a delimiter line (the `--` of the close delimiter and linear whitespace) was applied only to a content line that had already outgrown `http_max_multipart_form_data_size`. Below that limit, `MultipartReadBuffer::nextImpl` and `skipToNextBoundary` took any line starting with the boundary for a delimiter, so a line such as `--<boundary>garbage` silently truncated the part.

The check is now shared: `isValidDelimiterSuffixByte` is used by the over-limit path in `readLine`, and `checkDelimiterSuffix` validates the complete line in both boundary recognizers. A line that starts with the boundary but is not a valid delimiter line is rejected as malformed input.

Added `05839_http_multipart_malformed_boundary_line`, where all lines stay far below both size limits.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (14b4256ad681) and resolved the conflict in src/Core/Settings.cpp: the descriptions of http_max_fields, http_max_field_name_size and http_max_field_value_size were changed on both sides, so I kept the text of this PR and appended the paragraph from master about the headers of HTTP responses read as a client.

Addressed the remaining review thread in 3a82c00: the multipart boundary recognizers now reject a line that starts with the boundary but is not a valid delimiter line, instead of silently truncating the part. New test: 05839_http_multipart_malformed_boundary_line.

Verified locally on the merged build: the new test and the 23 other multipart / external-table HTTP tests of this PR pass.

/// But we could not just skip all parameters with suffixes '_format', '_types', '_structure',
/// because some of them are used in the query as a settings, like 'date_time_input_format',
static const Names reserved_param_suffixes = {"_format", "_types", "_structure"};
static const Names reserved_param_suffixes = {"_format", "_types", "_structure", "_decompress", "_disable_checksum"};

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.

[Major] Adding _decompress and _disable_checksum to this generic suffix skip breaks legitimate handler/query parameters on any multipart request with external tables. The main parameter loop checks param_could_be_skipped before customizeQueryParam, so param_codec_decompress=..., a declared handler parameter like foo_disable_checksum, or even a custom query_param_name ending with one of these suffixes is discarded here as soon as has_external_data is true. That turns unrelated handlers into "missing parameter" / "query not found" failures that were not external-table metadata before this change.

Can we either let customizeQueryParam claim handler/query parameters first, or exempt param_* / declared handler parameters from this suffix filter and apply it only to otherwise-unrecognized names?

@stresshouse

stresshouse Bot commented Nov 21, 2026

Copy link
Copy Markdown

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — inconclusive across 29 queries analysed

PR verdict: not_sure. 1 measured difference(s) not attributable to this PR. clickbench Q31: The measured difference cannot be attributed to this PR from the available source evidence. Tested merge a501b50a (first parent 6a2b727a, PR head e317f3d) changes src/Core/ExternalTable.cpp, src/Server/HTTP/HTMLForm.cpp/.h, src/Server/HTTPHandler.cpp, src/Core/Settings.cpp (doc strings only) and src/Compression/CompressedReadBufferBase.cpp/.h. This query is a GROUP BY WatchID, ClientIP over hits. It does read MergeTree columns through CompressedReadBufferBase::readCompressedData, but the new code there is two if (decompressed_size_limit) / if (compressed_size_limit) checks. Both default …

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 31 not_sure 243 211 -13.2% <0.0001 aggregation: The measured difference cannot be attributed to this PR from the available source evidence. Tested merge a501b50a (first parent 6a2b727a, PR head e317f3d) changes src/Core/ExternalTable.cpp, src/Server/HTTP/HTMLForm.cpp/.h, src/Server/HTTPHandler.cpp, src/Core/Settings.cpp (doc strings only) and src/Compression/CompressedReadBufferBase.cpp/.h. This query is a GROUP BY WatchID, ClientIP over hits. It does read MergeTree columns through CompressedReadBufferBase::readCompressedData, but the new code there is two if (decompressed_size_limit) / if (compressed_size_limit) checks. Both default …

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 02446ad3-7e03-4ed4-af24-323a07c59e4e
  • MIRAI run: 679c56eb-955d-4d49-8bda-9fce39f2b199
  • PR check IDs:
    • clickbench_577890_1795223436
    • clickbench_577896_1795223436
    • tpch_adapted_1_official_577902_1795223436
    • tpch_adapted_1_official_577917_1795223436

This branch has not been deployed

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

Labels

can be tested Allows running workflows for external contributors comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants