Skip to content

Ignorelist third-party Thrift protocol for UBSan - #111186

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/ubsan-ignorelist-thrift-protocol
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/ubsan-ignorelist-thrift-protocol

Conversation

@groeneai

@groeneai groeneai commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Description

Ignorelist third-party Thrift for UBSan.

Stress test (arm_asan_ubsan, s3) reported (STID 3543-4a91):

contrib/thrift/lib/cpp/src/thrift/protocol/TCompactProtocol.h:160:49:
runtime error: signed integer overflow: 2133724293 * 2 cannot be represented in type 'int'

Line 160 is trans_->checkReadBytesAvailable(map.size_ * elmSize) in TCompactProtocol::checkReadBytesAvailable(TMap&). map.size_ (int32) and elmSize are read from the compact-protocol wire (corrupt/fuzzed Parquet/ORC metadata), so a large declared map cardinality overflows signed int. This is vendored third-party Thrift arithmetic; the read it guards is still bounded and rechecked by the transport, so there is no unbounded read or allocation in a release build. Only the UBSan sanitizer build aborts on the overflow.

The same size * element-size idiom is present in the TSet/TList overloads and in TBinaryProtocol/TProtocol. Add src:*/contrib/thrift/lib/cpp/src/thrift/protocol/* to tests/ubsan_ignorelist.txt, scoped to the protocol sources (like the existing contrib/boost/boost/geometry subtree entry), consistent with the existing third-party UBSan entries.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110171&sha=b3699207b14e085180bef427dac73696403b023c&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29

Stress test (arm_asan_ubsan, s3) reported (STID 3543-4a91) a signed integer
overflow at contrib/thrift/lib/cpp/src/thrift/protocol/TCompactProtocol.h:160:49
= trans_->checkReadBytesAvailable(map.size_ * elmSize) in
checkReadBytesAvailable(TMap&). map.size_ (int32) times elmSize (int) is read
from the compact-protocol wire (corrupt/fuzzed Parquet/ORC metadata) and
overflows signed int. The same size times element-size idiom is present in the
Set and List overloads and in TBinaryProtocol and TProtocol. This is vendored
third-party Thrift arithmetic; the read it guards stays bounded and rechecked
by the transport, so release builds are unaffected and only the UBSan
sanitizer build aborts.

Ignorelist the Thrift protocol sources for UBSan, consistent with the existing
contrib/boost/boost/geometry and contrib/protobuf entries.

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

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

Independent second-model (codex) review of this diff.

⚠️ Majors

  • thrift-global-suppression — AGREE (partial). First-pass review flagged that a blanket src:*/contrib/thrift/* glob would disable UBSan across all of Thrift to hide one confirmed overflow. Confirmed the overflowing size * element-size idiom lives only in the protocol sources (TCompactProtocol/TBinaryProtocol/TProtocol, in the TSet/TList/TMap overloads), so narrowed the entry to src:*/contrib/thrift/lib/cpp/src/thrift/protocol/* (subtree-scoped like the existing boost/geometry entry) before opening this PR. DISAGREE on "patch/fix third-party Thrift instead": the established convention in this file is to ignorelist third-party UBSan (boost/geometry, protobuf, libprotobuf-mutator), not fork the vendored submodule, and the guarded read stays bounded and rechecked by the transport in release builds.

Re-run on the final diff: 0 findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A - config-only sanitizer-ignorelist change (like a CI/harness flaky-setting change). Underlying UBSan report is 1 hit / 60d on fuzzed Parquet; not deterministically reproducible and not required for a third-party ignorelist entry.
b Root cause explained? Yes - signed-int overflow of map.size_ * elmSize (int32 size_ times int element size) on wire-controlled sizes in third-party Thrift TCompactProtocol::checkReadBytesAvailable.
c Fix matches root cause? Yes - the report originates in contrib/thrift; ignorelisting the Thrift protocol sources stops UBSan aborting on that third-party arithmetic. Not a band-aid over a ClickHouse bug (the code is upstream Thrift's; the downstream read is bounded).
d Test intent preserved / new tests? N/A - no ClickHouse test changed or weakened; no ClickHouse-code UBSan coverage is disabled, only third-party Thrift.
e Demonstrated both directions? N/A (config-only). The -fsanitize-ignorelist glob matches the reporting file (header-only inline, same way the boost/geometry glob matches inline boost headers), so the overflow is no longer instrumented.
f General, not a narrow patch? Yes - scoped to contrib/thrift/lib/cpp/src/thrift/protocol/*, covering the same size * element-size idiom in the TSet/TList/TMap overloads and in TBinaryProtocol/TProtocol, not just line 160.
g Generalizes across inputs? Yes - TMap/TList/TSet variants and any wire-declared size all fall under the same ignorelist glob.
h Backward compatible? Yes - sanitizer-build-only config; no release behavior, wire, disk, or setting change.
i Invariants preserved? Yes - does not touch ClickHouse code paths; the guarded read remains bounded/rechecked by the transport in all builds.

Session id: cron:clickhouse-author-slot-1:20260721-074100

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @pamarcos - could you review this? It adds a UBSan ignorelist entry for the third-party Thrift protocol sources (contrib/thrift/lib/cpp/src/thrift/protocol/*), where checkReadBytesAvailable multiplies a wire-controlled map/list/set size by the element size and overflows signed int on corrupt/fuzzed Parquet metadata (STID 3543-4a91). Scoped like the existing boost/geometry entry.

@pamarcos pamarcos self-assigned this Jul 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0a0b2ef]

Summary: ❌

job_name test_name status info comment
Config Workflow FAIL
can_be_tested FAIL
Dockers Build (amd) DROPPED
Dockers Build (arm) DROPPED
Dockers Build (multiplatform manifest) DROPPED
Style check DROPPED
Code Review DROPPED
Docs check DROPPED
Docs check (Mintlify) DROPPED
Fast test DROPPED
CI Tests DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 21, 2026
@pamarcos

pamarcos commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Apache Thrift already fixed this exact defect, including regression tests, in 983c813c (apache/thrift@983c813).

@oranjeai my suggestion is to sync v0.24.0 to our fork to include that commit. Then, cherry-pick the additions we had in v0.23.0 to the original version: ClickHouse/thrift@f95a731 and ClickHouse/thrift@248688d. Do that in a separate PR, I'm closing this one.

@pamarcos pamarcos closed this Jul 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Acknowledged. I'll sync ClickHouse/thrift to Apache Thrift v0.24.0 (which includes 983c813c), cherry-pick f95a731b and 248688d4 on top, then open a new PR bumping the contrib/thrift submodule and dropping the UBSan ignorelist entry. I'll post the new PR link here.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Opened the sync as ClickHouse/thrift#10: base Apache Thrift v0.24.0 (includes 983c813c + its regression tests) with f95a731b ("Don't use locale in to_string") cherry-picked on top.

248688d4 ("Remove nested submodules") was a no-op on v0.24.0 and skipped: v0.24.0 upstream has no .gitmodules / nested submodule dirs, so the cherry-pick came up empty.

Verified inside ClickHouse: _thrift and _arrow (the Parquet metadata consumer) both compile and link against the new tree; the overflow site is now static_cast<int64_t>(size_) * elmSize.

I don't have push access to ClickHouse/thrift, so #10 comes from a fork branch targeting master (a clean ancestor of v0.24.0). If you'd rather track it as a ClickHouse/v0.24.0 release branch (matching the ClickHouse/v0.23.0 convention the submodule pins), the fork head is named ClickHouse/v0.24.0 and can be used as-is. Once #10 lands I'll bump the contrib/thrift submodule in a follow-up ClickHouse PR.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Follow-up on the v0.24.0 sync: @thevar1able created the ClickHouse/v0.24.0 branch in ClickHouse/thrift (Apache Thrift v0.24.0, which contains 983c813c, plus f95a731b cherry-picked). Opened the ClickHouse-side submodule bump: #111278

master's tests/ubsan_ignorelist.txt had no Thrift entry (it only lived on this PR's branch), so nothing needed removing.

pull Bot pushed a commit to TCeason/ClickHouse that referenced this pull request Jul 29, 2026
Point contrib/thrift at the ClickHouse/thrift ClickHouse/v0.24.0 branch
(13d30d6a): Apache Thrift v0.24.0 with the ClickHouse patch f95a731b
("Don't use locale in to_string") cherry-picked.

v0.24.0 includes Apache commit 983c813c, which widens the compact-protocol
container-size prechecks to int64 (static_cast<int64_t>(size_) * elemSize),
fixing a signed-integer overflow on wire-controlled sizes. This is the
upstream fix for UBSan finding STID 3543-4a91, superseding the ubsan_ignorelist
approach from ClickHouse#111186 (closed) as suggested by @pamarcos.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants