Skip to content

Cherry pick #116564 to 26.8: Fix a crash on an Iceberg manifest list with a huge manifest_length - #128616

Merged
PedroTadim merged 4 commits into
backport/26.8/116564from
cherrypick/26.8/116564
Nov 2, 2026
Merged

PedroTadim merged 4 commits into
backport/26.8/116564from
cherrypick/26.8/116564

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #116564

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits August 26, 2026 17:15
An Iceberg manifest-list entry declares manifest_length, and that declared
number became ManifestFileCacheableInfo::file_bytes_size, whose only reader is
the metadata cache cell weight: 3 * file_bytes_size + 200. The cache policy
adds that to current_size_in_bytes, and SLRUCachePolicy::removeOverflow ends
with

    if (current_size_in_bytes > (1ull << 63))
        std::terminate(); // Queue became inconsistent

so any declared value above (2^63 - 200) / 3 = 3074457345618258536 terminates
the server. It is abnormal termination rather than an exception, so a release
build dies with an empty response to the client and nothing in the log.

The mechanism is magnitude, not signedness. memory_bytes was declared Int64 and
the huge size_t expression was narrowed into it, but the weight function
converts it straight back to size_t and recovers the identical bit pattern, and
the guard that fires is a magnitude test. Building the Int64 -> size_t change on
its own still reproduces the abort; that hunk is type correctness, matching the
weight function's own return type, not the fix.

The fix is to stop letting a metadata-declared number reach the weight at all.
getManifestFile now takes the manifest file's size from the object storage,
which createReadBuffer already populates unconditionally and which the function
previously discarded, so there is no extra request. The size_t bytes_size
parameter is deleted, which fixes all three call sites structurally: there is
nowhere left to pass a declared length. This mirrors the Paimon sibling, which
was never vulnerable, and it makes the read side use the same definition of
manifest_length the write side already uses, getObjectMetadata(...).size_bytes.

Confirmed the abort site under gdb with a breakpoint conditioned on the Iceberg
cell, since the two identical std::terminate() blocks in that function are tail
merged and a plain backtrace attributes the frame elsewhere: it is the magnitude
check, reached from the protected-queue pass of set, with current_size_in_bytes
= 13835058055282168350 for a declared 2^62. The other std::terminate() in the
same function is not reachable on this path, because the eviction loop guarding
it does not run. Exposure is limited to the default SLRU policy; LRU evicts the
oversized cell before reaching its own equivalent check.

ManifestFileCacheKey::manifest_file_byte_size keeps the declared value and now
has no readers. It is left in place deliberately: the struct is a faithful
record of a manifest-list entry, and removing it would conflict with #90740,
which edits that construction line.

Regression coverage is an integration test rather than a functional one, because
the shape needs a hand-written Avro manifest list and a functional test may not
fabricate metadata files. It reuses the existing Avro harness in
test_storage_iceberg_no_spark and carries a control arm that performs the same
manifest-list round trip without changing the value, so "any rewrite breaks it"
cannot masquerade as the finding. The control is ordered first: the defect
aborts the server and the package fixture is stay_alive, so running the huge
case first makes the control fail with a connection error instead of reporting
its own result.

Closes: #116496

Co-Authored-By: Claude Opus 5 <[email protected]>
The cell weight was taken from `manifest_object_info.metadata->size_bytes`, which
`createReadBuffer` leaves at `0` whenever the storage does not report a size:
`getObjectInfo.cpp:75-76` sets `is_size_known = ContentLengthHasBeenSet()`, so an S3
HEAD without `Content-Length` yields `0`, and `WebObjectStorage.cpp:399-402` is a second
carrier. A manifest cached on that path weighed only the 200-byte floor, so the
128 MiB `iceberg_metadata_files_cache_size` stopped bounding it and only the 1000-entry
limit remained. Before this PR the weight came from the manifest list's declared
`manifest_length`, which is always present, so this was a regression introduced here.

`AvroForIcebergDeserializer`'s constructor already drains the whole file, so the bytes it
read are the file's size on storage and need no cooperation from the storage layer.
`AvroInputStreamReadBufferAdapter::byteCount()` is already `in.count()`, so this is the
existing idiom rather than a new one.

Measured weight-preserving, not merely plausible: on the same table
`system.metrics.IcebergMetadataFilesCacheBytes` is bit-identical before and after
(31815, and 123882 on a second fixture). That equality is not vacuous, because the
declared length works as a knob that proves the cell's weight lands in that metric with
coefficient 3: with `manifest_length` set to 1000000 on a 9064-byte manifest, the pre-fix
build reports 3004626 against 31818, a delta of exactly 3 * (1000000 - 9064), while both
fixed builds ignore the declared number.

The regression test now asserts that weight against the manifest's real size on disk,
read from the file rather than hardcoded so that it stays stable as the fixture moves.
Charging the cell from a declared `1` instead makes it fail (`weight 4695 < 3 * 9085`)
while the result assertions still pass, so the bound is what catches a weight that does
not come from the real size.

Its read-back queries also pin `use_iceberg_metadata_files_cache`. Without the pin the
test depends on the setting's default: with it flipped off, the poisoned case passes
against a pre-fix binary, i.e. the test goes blind while still looking green.
…cache-weight

Fix a crash on an Iceberg manifest list with a huge manifest_length
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 2, 2026
@PedroTadim
PedroTadim merged commit 35dc519 into backport/26.8/116564 Nov 2, 2026
176 of 189 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.8/116564 branch November 2, 2026 12:40

This branch was successfully deployed

1 active deployment
staging - docs — d6d200b4 Deployed Aug 28, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants