Skip to content

Reject metadata_type = web on a non-web object storage - #119818

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/119798-web-metadata-type-check
Sep 15, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/119798-web-metadata-type-check

Conversation

@groeneai

@groeneai groeneai commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix

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

Fixed a crash when a disk is configured with metadata_type = web or metadata_type = web_index on top of a non-web object storage. Such a configuration is now rejected with INVALID_CONFIG_PARAMETER instead of interpreting an unrelated object storage as a web one. Closes #119798.

Description

Closes #119798

A single CREATE TABLE terminated the server:

CREATE TABLE t (a Int32) ENGINE = MergeTree ORDER BY a
SETTINGS disk = disk(name='d', type='object_storage', object_storage_type='local',
                     path='/tmp/blobs/', metadata_type='web',
                     read_only=1, skip_access_check=1);

I reproduced the SIGSEGV on official builds 26.8.2.3 and 26.9.1.410, and on a debug build of
master. metadata_type = web_index fails identically.

Root cause: nothing validated the object_storage_type / metadata_type pairing. An explicit
metadata_type overrides the compatibility hint unconditionally, and the web / web_index
handlers asserted their requirement with assert_cast, whose typeid check is compiled out in this
translation unit (assert_cast.h does not include the header that defines
DEBUG_OR_SANITIZER_BUILD, and it was this file's first include). A LocalObjectStorage was
therefore static_cast to WebObjectStorage, and getBaseURL() read url_shards at a bogus
offset from MergeTreeData::initializeDirectoriesAndFormatVersion.

Change: both downcasts now go through one helper doing dynamic_cast plus a typed
INVALID_CONFIG_PARAMETER, in the metadata storage factory that is the single choke point for XML
config, SETTINGS disk = disk(...), ATTACH and table load. No setting, no default and no format
change; the only configurations affected are the ones that today reinterpret one object storage as
another, and they are now rejected when the disk is created.

Validation: the two new cases in 02963_test_flexible_disk_configuration fail on master and pass
with the fix (50/50 repeats clean); the existing type = web disk tests 03057, 03355, 03823
and 04033 all still pass, which is what would catch a guard wrongly rejecting a real web disk.


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

Version info

  • Merged into: 26.9.1.1510 (included in 26.9 and later)

A disk configured with metadata_type = web (or web_index) on top of a
non-web object storage crashed the server with a SIGSEGV, reachable from a
single CREATE TABLE:

    CREATE TABLE t (a Int32) ENGINE = MergeTree ORDER BY a
    SETTINGS disk = disk(name='d', type='object_storage',
                         object_storage_type='local', path='/tmp/blobs/',
                         metadata_type='web', read_only=1, skip_access_check=1);

Nothing validated the object_storage_type / metadata_type pairing: an
explicit metadata_type overrides the compatibility hint unconditionally,
and the two handlers that require a concrete WebObjectStorage asserted that
requirement with assert_cast. That typeid check is compiled out in this
translation unit, because assert_cast.h does not include the header that
defines DEBUG_OR_SANITIZER_BUILD and it was this file's first include, so
the cast was a bare static_cast in every build flavour. A LocalObjectStorage
was reinterpreted as a WebObjectStorage and getBaseURL() read
url_shards.front().front() at a bogus offset, reached from
MergeTreeData::initializeDirectoriesAndFormatVersion.

Both downcasts now go through one helper that does a dynamic_cast and
throws INVALID_CONFIG_PARAMETER, validating and casting in one operation.
The metadata storage factory is the single choke point for XML config,
SETTINGS disk = disk(...), ATTACH and table load, so no path can hand a
non-web object storage to these two metadata storages any more.
Reproduced on official builds 26.8.2.3 and 26.9.1.410.

Closes ClickHouse#119798
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review: my own cold read of the diff first, then an independent model
(engine: codex, 1 finding), then adjudication. 7 items, 0 blockers, 0 majors in the source change.

# Sev Finding Verdict Evidence / action
1 ⚠️ The draft PR body claimed an XML-configured disk with this pairing crashes during DiskSelector initialization at server start AGREE, fixed before publishing Never measured, and the code says otherwise: Server.cpp passes global_skip_access_check = false, so the disk access check reaches an unimplemented write on the read-only web metadata storage and throws NOT_IMPLEMENTED before anything dereferences the mis-cast object. That is exactly the Code: 48 the new test cases get on unmodified master. Sentence removed
2 💡 The body said only configurations that crash today change behaviour AGREE, fixed before publishing A disk with skip_access_check = 1 that is never read starts fine today, so the affected set is the mis-paired configurations, not the crashing ones. Reworded
3 💡 Changelog entry did not carry Closes #119798 AGREE, fixed before publishing Added
4 💡 The new error message names the metadata type and the object storage class but not the offending disk AGREE, noted, not changed The sibling guard in the same file (Disk supports only single location clusters) names no disk either, so I kept the file's house style rather than diverge in a crash fix
5 💡 The title names only web, though both web and web_index are fixed AGREE, noted, not changed True. The changelog entry, the description and the diff all name web_index, so the scope is unambiguous; I had already frozen the PR contract before the independent pass ran, and I would rather not re-open it for a cosmetic edit
6 💡 Suggested selecting Critical Bug Fix instead of Bug Fix, since the defect terminates the server DISAGREE My standing instruction is never to self-select Critical Bug Fix; I pick it only when a maintainer asks for it, and the request here was for a fix, not a category. The reading of the template is fair, so if you want it re-labelled, please do, or say so and I will change it
7 💡 Suggested writing the relationship as a full Closes: <url> line in the template's linked-issues block DISAGREE That block is an HTML comment and I keep it byte-identical to the upstream template. Closes #119798 is already present in the changelog entry, in the description and in the commit message, so the issue auto-closes on merge

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Checks I ran while reading, recorded because they are the ones that would have caught a bad fix:

  • The guard cannot reject a working configuration. ObjectStorageFactory::create never wraps, and
    the only CachedObjectStorage is built in DiskObjectStorage::wrapWithCache, which reuses the
    already-built metadata storage and never re-enters the metadata storage factory. So no cache
    layer can reach the new dynamic_cast. This is also why dynamic_cast is the right tool here
    and a getType() check is not: CachedObjectStorage::getType() forwards to the storage it
    wraps.
  • WebObjectStorage is not final, so dynamic_cast accepts a legitimate subclass that
    assert_cast's exact-typeid check would have rejected.
  • The message uses getName() (Local, S3, Web), not getDescription(), so no endpoint or
    credential can reach the exception text.
  • Both web metadata storages construct only at the two changed lines, so the guard is complete.
  • takePointingTo is .at(), so the error branch cannot dereference a null object storage.
  • The two new test cases are red on unmodified master and green with the fix, because the guard
    raises at disk creation, strictly before both the access check and the getBaseURL() read. I
    deliberately did not add a skip_access_check = 1 case that reproduces the segfault itself: the
    category makes CI run these cases against a build without the fix, where a segfault would take
    the shared server and every concurrent test down with it.

One thing I noticed and am not raising: StorageObjectStorageSource.cpp casts to
WebObjectStorage behind a getType() != Web check, which a cache wrapper forwards through. I
have not measured whether that path is reachable, so I am not speculating about it here or
widening this fix.

Session id: cron:clickhouse-review-slot-8:20260913-172400

@clickhouse-gh clickhouse-gh Bot closed this Sep 13, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100% on every run, no randomization involved: one CREATE TABLE ... SETTINGS disk = disk(object_storage_type='local', metadata_type='web', read_only=1, skip_access_check=1). SIGSEGV on official builds 26.8.2.3 and 26.9.1.410 and on a debug build of master; identical for metadata_type='web_index'. Control metadata_type='plain_rewritable' exits 0.
b Root cause explained? Yes. An explicit metadata_type overrides the compatibility hint unconditionally and nothing validates the pairing, so the web handler assert_casts the disk's object storage to WebObjectStorage. That typeid check is compiled out in this translation unit (assert_cast.h does not include the header defining DEBUG_OR_SANITIZER_BUILD and was this file's first include, proven by preprocessing the TU), so a LocalObjectStorage is static_cast and getBaseURL() reads url_shards.front().front() at a bogus offset. gdb: getBaseURL <- loadFiles <- tryGetFileInfo <- existsFile <- IDisk::readFileIfExists <- MergeTreeData::initializeDirectoriesAndFormatVersion.
c Fix matches root cause? Yes. The mis-cast itself is removed: dynamic_cast validates and casts in one operation and throws INVALID_CONFIG_PARAMETER at the factory that owns the requirement. Not a widened bound, not a no-random-* tag, and not a guard at the crash site, which is untouched.
d Test intent preserved / new tests added? Yes. 02963_test_flexible_disk_configuration gains two cases, one per fixed code site; every pre-existing case is unchanged and .reference stays empty.
e Both directions demonstrated? Yes, on Build-ID-verified binaries. Without the fix the test fails (Expected server error code: 318 but got: 48) and the raw repro SIGSEGVs; with the fix the test passes and both statements return Code: 318. 50/50 randomized repeats pass.
f Fix is general across code paths? Yes. Both unvalidated downcasts in the factory (web and web_index) are fixed together. The same cast in StorageObjectStorageSource.cpp:180 is already guarded; the other assert_cast sites in disks already use dynamic_cast plus a null check. The remaining metadata_type handlers use only virtual IObjectStorage API, so they carry no concrete-type requirement. The factory has one production caller, so XML config, DDL, ATTACH and table load all pass through the fixed point.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, the guard is type-based and so uniform by construction; verified on a second object storage type as well (object_storage_type='s3' + metadata_type='web' gives Code: 318 ... configured with S3 object storage). Both metadata types verified in both directions. dynamic_cast additionally accepts a legitimate WebObjectStorage subclass, which assert_cast's exact-typeid check would have rejected.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, no default change, no serialization or format change, so no SettingsChangesHistory.cpp entry is required. No working setup is broken: such a disk is created eagerly, so this pairing already crashed at table creation or at server start.
i Invariants and contracts preserved? Yes. The invariant made explicit is that a metadata storage requiring a concrete WebObjectStorage never receives anything else, in any build flavour. Both web metadata storages hold a const WebObjectStorage & that is now guaranteed to refer to a real WebObjectStorage, which is strictly stronger than before. The helper throws before either object is constructed, so no partially built state exists on the error path, and it reuses the disk-creation error path already used by the sibling configuration rejections. No lock or concurrency contract is touched.

Session id: cron:clickhouse-impl-slot-5:20260913-164502

@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [90a728e]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted) FAIL
Logical error: Can't determine table for parallel replicas (STID: 3634-4123) FAIL cidb IGNORED

AI Review

Summary

This PR hardens MetadataStorageFactory so metadata_type = web and metadata_type = web_index validate the underlying backend with dynamic_cast and fail fast with INVALID_CONFIG_PARAMETER instead of letting a non-web backend reach WebObjectStorage-specific code. I checked the full factory path, the surrounding WebObjectStorage and metadata implementations, the cache-wrapping lifecycle, and the added stateless coverage, and I did not find a remaining correctness gap in the current diff.

Final Verdict

✅ No new findings. I did not post any inline review comments.

LLVM Coverage Report

Measured on commit 90a728e.

Metric Baseline Current Δ
Lines 89.00% 89.10% +0.10%
Functions 91.80% 91.80% +0.00%
Branches 81.50% 81.50% +0.00%

Changed lines: Changed C/C++ lines covered: 14/15 (93.33%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... labels Sep 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 90a728e08 with master cc102704b (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 17 s compile time in total, 8 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - af61629

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted, old_compatibility) / Logical error: Can't determine table for parallel replicas (STID 3634-4123) logical error thrown in src/Planner/findParallelReplicasQuery.cpp on a fuzzer-generated query that nests viewExplain('EXPLAIN', ...) inside a subquery, so the planner finds no eligible physical table; 8 distinct PR carriers and 0 master rows over 30 days, and this branch only adds a metadata-type check in MetadataStorageFactory #110020 (mine, open)
Stress test (arm_msan) / Hung check failed, possible deadlock found cancelled INSERT, is_cancelled = 1 after 1148 s, whose two writer threads are still inside the MergeTreeDataPartWriterWide::writeSingleGranule granule loop serializing JSON Object / Dynamic / Variant columns while the initiator waits in CompletedPipelineExecutor::execute(): that loop body has no cancellation point, so the query cannot stop within the probe window #108357 (external, open)
CH Inc sync - CH Inc sync (private, not actionable by me)

Mergeable Check and PR are the praktika aggregators; they are red only because of the two job rows above.

Session id: cron:our-pr-ci-monitor:20260913-223048

@PedroTadim PedroTadim self-assigned this Sep 14, 2026
@PedroTadim PedroTadim added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-bugfix Pull request with bugfix, not backported by default labels Sep 14, 2026
@PedroTadim PedroTadim added pr-bugfix Pull request with bugfix, not backported by default and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Sep 15, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Sep 15, 2026
Merged via the queue into ClickHouse:master with commit 22be007 Sep 15, 2026
175 of 177 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 15, 2026
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-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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

Development

Successfully merging this pull request may close these issues.

Disk with metadata_type = web on a non-web object storage segfaults

3 participants