Skip to content

Sync to Apache Thrift v0.24.0 (fixes container-size UBSan overflow) + re-apply f95a731b - #10

Closed
groeneai wants to merge 541 commits into
ClickHouse:masterfrom
groeneai:ClickHouse/v0.24.0
Closed

groeneai wants to merge 541 commits into
ClickHouse:masterfrom
groeneai:ClickHouse/v0.24.0

Conversation

@groeneai

Copy link
Copy Markdown

Sync the ClickHouse Thrift fork to Apache Thrift v0.24.0 and re-apply the one ClickHouse-specific C++ patch that is still needed.

Why

ClickHouse's contrib/thrift currently pins ClickHouse/v0.23.0 (Apache v0.23.0 + 2 ClickHouse commits). UBSan flags a signed-integer overflow (STID 3543-4a91) in checkReadBytesAvailable when reading fuzzed/corrupt Parquet metadata:

trans_->checkReadBytesAvailable(map.size_ * elmSize);   // int32 size_ * int elmSize

Apache Thrift fixed this in 983c813c ("Widen multiplication operands in container size prechecks to prevent arithmetic overflow"), which casts the size to int64_t before the multiply, and it is included in tag v0.24.0 (together with its regression tests, lib/cpp/test/ThrifttReadCheckTests.cpp). This supersedes the UBSan-ignorelist workaround proposed in ClickHouse/ClickHouse#111186 (closed).

What this branch contains

  • Base: Apache Thrift v0.24.0 (includes the 983c813c overflow fix + upstream hardening/tests).
  • Cherry-pick of the ClickHouse-specific v0.23.0 addition f95a731b ("Don't use locale in to_string").

The other v0.23.0 addition, 248688d4 ("Remove nested submodules"), is a no-op on v0.24.0: v0.24.0 upstream has no .gitmodules and no nested submodule directories, so there is nothing to remove. It was skipped for that reason (the cherry-pick was empty).

Verified

Built the resulting tree inside ClickHouse (the only consumer of this fork, via contrib/arrow-cmake for Parquet and contrib/hive-metastore-cmake):

  • _thrift static library compiles and links against v0.24.0; the explicit source list in contrib/thrift-cmake/CMakeLists.txt still matches (no missing sources).
  • _arrow (the Parquet metadata consumer that exercises checkReadBytesAvailable) compiles and links against the new protocol/transport headers with no ABI break.
  • The overflow site is now static_cast<int64_t>(size_) * elmSize in TSet/TList/TMap overloads across TCompactProtocol.h, TBinaryProtocol.h, TProtocol.h.

Note on target branch

I don't have push access to ClickHouse/thrift, so this comes from a fork branch. I targeted master because it is a clean ancestor of v0.24.0 (the diff is purely additive). If you prefer to track this as a ClickHouse/v0.24.0 release branch (matching the existing ClickHouse/v0.22.0 / ClickHouse/v0.23.0 convention that the submodule pins), the branch head pushed to my fork is ClickHouse/v0.24.0 and can be used as-is. Once this lands, I'll open the contrib/thrift submodule bump in ClickHouse/ClickHouse.

Per ClickHouse/ClickHouse#111186 (@pamarcos).

Jens-G and others added 30 commits April 17, 2026 00:24
Client: php

Generated-by: Codex GPT-5.4
Client: netstd

Co-Authored-By: Hasnain Lakhani <[email protected]>
Co-Authored-By: Jens Geyer <[email protected]>
Generated-by: Claude Opus 4.6
Source-level breakage of the fuzzer projects was going undetected
because `make build-fuzzers` is opt-in (it needs the SharpFuzz CLI
and libfuzzer-dotnet, which CI does not carry). Compile all 12
fuzzer variants as part of `make check` instead, skipping SharpFuzz
IL rewriting — the actual instrumented build stays opt-in.

- buildfuzzers.sh: new --no-instrument flag that skips the
  SHARPFUZZ_DIR / libfuzzer-dotnet / sharpfuzz-CLI preflight checks
  and the post-build instrumentation pass.
- lib/netstd/Makefile.am: check-local gains a precompile-fuzzers
  dependency that invokes `./buildfuzzers.sh --no-instrument`. The
  old build-fuzzers target is rewritten to delegate to the shell
  script as well (it previously skipped code generation and would
  fail on a clean tree). gen-netstd added to clean-local, and both
  shell drivers added to EXTRA_DIST so `make dist` includes them.
- README: fuzzing section updated.

Requested by @mhlakhani in PR apache#3402.

Client: netstd

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Client: rb

Co-Authored-By: OpenAI Codex (GPT-5.4) <[email protected]>
Client: py

Adds _max_decompressed_size (default: HARD_MAX_FRAME_SIZE) and
set_max_decompressed_size() to THeaderTransport. ZLIB decompression
now uses decompressobj with a size cap instead of unbounded
zlib.decompress(), consistent with the C++ implementation.

Refactor THeaderTransport read-transform dispatch into _apply_read_transform

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Client: rb

Ruby is on a gradual path toward frozen string literals by default. That
transition began in Ruby 3.4.0 with chilled strings, but we can get the
benefits today by explicitly enabling `# frozen_string_literal: true`.
Doing so reduces avoidable string allocations and copies, lets the VM do
less work, removes many manual .freeze workarounds, and can deliver
meaningful performance improvements in allocation-heavy code paths.

This change adds frozen string literal to all generated files, and also
library files. There is one performance issue in JSON protocol I noticed
where we used += on strings instead of <<, which allocates much more
objects than necessary, and you can clearly see the gain in the profile
table below.

Co-Authored-By: OpenAI Codex (GPT-5.4) <[email protected]>
Client: py

C++ and Go already enforce a limit of 64 recursive skip() calls via
TInputRecursionTracker and maxDepth respectively. This change adds an
equivalent max_depth=64 parameter to the Python skip() implementation
in TProtocolBase, raising TProtocolException(DEPTH_LIMIT) when the
limit is exceeded.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Client: py

The module-level _match_hostname was defined inline as a no-op lambda,
shadowing the more complete implementation already exported by sslcompat.
Use the sslcompat version directly, removing the duplicate definition.
Python 3.12+ removed ssl.match_hostname entirely; the sslcompat fallback
is a no-op on that version by design.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Client: php

Generated-by: Codex GPT-5
Client: py,go,php,java,netstd,delphi,haxe,lua,swift,rb,dart,erl,rs

C++ and Node.js already enforce a 10-byte ceiling on varint reads.
This change brings all remaining runtimes into parity by raising a
protocol exception (INVALID_DATA) when more than 10 bytes are consumed
without finding a terminating byte.

Java: both fast-path and slow-path varint readers are covered.
Erlang: read_varint/3 gains a when Count < 10 guard clause; call sites
  updated to propagate the error tuple rather than crashing on badmatch.
Rust: VarIntReader trait replaced with local bounded loops; zigzag
  decode moved to free functions independent of the integer_encoding crate.
Ruby: both the pure-Ruby implementation and the C extension are fixed;
  read_varint32 gains a separate 5-byte limit instead of delegating to
  read_varint64.

Named constants replace bare integer literals in all runtimes, with a
comment explaining the derivation (ceil(64/7) = 10, ceil(32/7) = 5).
Java and Rust enforce both the 5-byte (32-bit) and 10-byte (64-bit)
limits; other runtimes enforce the 10-byte ceiling uniformly.

Tests added for py, go, php, java (all four original runtimes), plus
rb, swift, dart, and rs which have existing unit-test infrastructure.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This allows to use named pipes from go-winio.
Client: java

TProtocolUtil.skip() previously defaulted to Integer.MAX_VALUE for its
recursion limit, making it effectively unbounded. This change aligns
the default with C++, Go, and Node.js (all use 64) by setting
maxSkipDepth to 64. Applications needing deeper nesting can still call
setMaxSkipDepth() to raise the limit.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Client: netstd
Patch: Jens Geyer
Client: java
Patch: Jens Geyer

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

This closes apache#3415
Client: java

Co-Authored-By: OpenAI Codex (GPT-5.4) <[email protected]>
clang 21 introduced -Wdefault-const-init-field-unsafe, which triggers on
Ruby 3.2's rstring.h because struct RString contains a const field (klass)
via RBasic. Since extconf.rb unconditionally adds -Werror, this new warning
causes the native extension build to fail.

The warning originates in Ruby headers, not Thrift code. Use append_cflags
to suppress it; append_cflags silently ignores unknown flags, so this is
safe on all older compiler versions.

Client: rb
THRIFT-5951: Add PHP runtime coverage tests
markjm and others added 19 commits June 26, 2026 23:58
…pache#3595)

* THRIFT-6069: python: avoid utf8 copy during fastbinary string encode
Client: py

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Client: c_glib

thrift_framed_transport_read_slow copies leftover bytes from the previous frame with memcpy(buf, t->r_buf, t->r_buf->len), passing the GByteArray struct pointer as the source instead of t->r_buf->data. The correct source is the buffer's data member, as used by the other memcpy calls in the same file. thrift_buffered_transport_read_slow contains the same mistake in its leftover path. Both are updated to read from t->r_buf->data, and a regression test using a memory buffer exercises the cross-boundary read path in each transport.

This closes apache#3607
…in lib/js

Upgrade jsdoc from ^3.6.7 to ^4.0.0 in lib/js and add an npm override
to force grunt-jsdoc to use jsdoc 4.x instead of 3.x. This eliminates
taffydb from the lib/js dependency tree.

lib/ts has no jsdoc dependency on current master, so no change needed there.

Client: js

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Generated-by: Claude Sonnet 4.6

This closes apache#3608
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 6.4.0 to 6.5.0.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](actions/setup-go@4a36011...924ae3a)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-version: 6.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps com.diffplug.spotless from 8.5.1 to 8.7.0.

---
updated-dependencies:
- dependency-name: com.diffplug.spotless
  dependency-version: 8.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [rust-lang/crates-io-auth-action](https://github.com/rust-lang/crates-io-auth-action) from 1.0.4 to 1.0.5.
- [Release notes](https://github.com/rust-lang/crates-io-auth-action/releases)
- [Commits](rust-lang/crates-io-auth-action@bbd8162...c6f97d4)

---
updated-dependencies:
- dependency-name: rust-lang/crates-io-auth-action
  dependency-version: 1.0.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [ruby/setup-ruby](https://github.com/ruby/setup-ruby) from 1.310.0 to 1.314.0.
- [Release notes](https://github.com/ruby/setup-ruby/releases)
- [Changelog](https://github.com/ruby/setup-ruby/blob/master/release.rb)
- [Commits](ruby/setup-ruby@afeafc3...9eb537c)

---
updated-dependencies:
- dependency-name: ruby/setup-ruby
  dependency-version: 1.314.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Client: cpp

Add explicit SSLContext(SSL_CTX* ctx) to wrap an application-configured
OpenSSL context via the existing SSLContextFactory hook. Document the
injection pattern and add SecurityTest coverage.
Bumps [rubygems/release-gem](https://github.com/rubygems/release-gem) from 1.2.0 to 1.4.0.
- [Release notes](https://github.com/rubygems/release-gem/releases)
- [Commits](rubygems/release-gem@6317d8d...052cc82)

---
updated-dependencies:
- dependency-name: rubygems/release-gem
  dependency-version: 1.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Client: cpp
Patch: Javid Khan <[email protected]>

when reading the key/value info headers of a THeader frame, readString reads
the length varint and then bounds it against the bytes left in the header
section. the comparison uses ptr before it is moved past the varint, so the
remaining count is overstated by the width of the length field, and a negative
length (a varint with the high bit set) is not rejected at all. with a header
section sized to fill the receive buffer, either case lets a wire-supplied
length exceed the header bytes that are actually present.

bound the length against the position that follows the varint, reject a
negative length, and only advance ptr once those checks pass so the documented
advance-on-success behaviour still holds. regression tests covering both the
oversized and the negative length are added to ThrifttReadCheckTests.

This closes apache#3610
The configure checks parsed the toolchain version with sed expressions that
only matched single-digit components (e.g. [0-9].[0-9].[0-9]).  Modern
toolchains such as go1.25.0 therefore did not match, and the raw, unparsed
command output -- including the "go: downloading ..." toolchain line and the
"linux/amd64" path -- was stored verbatim in golang_version / rustc_version.

That value (a multi-line string containing a '/') broke AX_COMPARE_VERSION's
internal sed and corrupted config.status, which made configure fail while
bootstrapping the dependency-tracking makefile fragments and produced a
malformed Makefile.

Anchor both expressions to the reported version line and accept multi-digit,
multi-component version numbers, yielding a clean value (e.g. 1.25.0 / 1.85.1).

Client: go,rs

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two files listed in the distribution no longer existed at their referenced
paths, so "make dist" aborted with "No rule to make target ...":

- Thrift.podspec was removed together with the Swift binding but was left
  behind in the top-level EXTRA_DIST.
- The netstd THttpServerTransport.cs was moved into
  Thrift.AspNetCore/Transport/Server/; point EXTRA_DIST at the Transport
  directory instead, matching the existing Thrift/Transport entry.

Client: netstd

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When lib/nodejs/test has been through "npm install", it contains a
node_modules/thrift symlink pointing back at the repo root (so the tests
can require('thrift')). "make dist" copies the whole test/ tree via
EXTRA_DIST and tars it with --hard-dereference, which follows that
self-referential link recursively until paths exceed tar's 256-char
limit, aborting the build with "file name is too long". It only
reproduces when node_modules is present, so a clean checkout never hits
it and CI did not catch it.

Prune node_modules from the distribution in the top-level dist-hook,
alongside the existing .git/.deps/.DS_Store handling. Also add
test/node_modules to the nodejs clean-local rule, which already removed
the episodic node_modules but not this one.

Client: nodejs

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adjust what "make dist" ships in the release tarball.

Dropped (build output and generated code that a built tree leaves behind,
swept in via whole-directory EXTRA_DIST entries and pruned in dist-hook;
none of it is tracked, so a clean checkout never contained it):
- lib/haxe/test/{bin,gen-haxe}, lib/javame/gen-javame
- lib/netstd bin/obj/gen-netstd across the test and benchmark projects
- test/netstd/{Client,Server}/ThriftTest
- tutorial/netstd/Interfaces/{shared,tutorial} (tracked project
  scaffolding is kept so the tutorial still builds from the tarball)
- test/cpp/gen-cpp* (nodist generated sources)
- build/__pycache__ and stray *.pyc
Also no longer shipped: the .github/ CI configuration and
doc/thrift-threat-model.md.

Added (tracked sources that were missing from EXTRA_DIST):
- lib/lua/test/{RecursionDepth.thrift,test_recursion_depth.lua}
- lib/netstd/Tests/codegen/run-NetStd-Codegen-Tests.ps1
- test/JsRecursionDepthTest.thrift
- lib/php/{phpstan.neon,phpstan-baseline.neon}
- SECURITY.md

Verified end-to-end with make dist in a clean container: 4317 -> 3480
tarball entries, and the only tracked files removed are .github/* and
doc/thrift-threat-model.md.

Client: netstd,haxe,javame,lua,php,cpp

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

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 10 committers have signed the CLA.

✅ al13n321
❌ jimexist
❌ Jens-G
❌ dxbjavid
❌ santiagomed
❌ HTHou
❌ vikrantpuppala
❌ hongzhi-gao
❌ bigjust
❌ markjm
You have signed the CLA already but the status is still pending? Let us recheck it.

@pamarcos pamarcos self-assigned this Jul 21, 2026
@thevar1able thevar1able self-assigned this Jul 21, 2026
@thevar1able

Copy link
Copy Markdown
Member

@groeneai please find guidelines on managing contribs in our documentation. In short: we pin to branch named 'ClickHouse/upstream-tag', not to master.

@pamarcos

Copy link
Copy Markdown
Member

If you prefer to track this as a ClickHouse/v0.24.0 release branch (matching the existing ClickHouse/v0.22.0 / ClickHouse/v0.23.0 convention that the submodule pins), the branch head pushed to my fork is ClickHouse/v0.24.0 and can be used as-is. Once this lands, I'll open the contrib/thrift submodule bump in ClickHouse/ClickHouse.

Yep, but for what's worth I think it already tried to do that, but it complained it doesn't have push access to create that branch

I don't have push access to ClickHouse/thrift, so this comes from a fork branch. I targeted master because it is a clean ancestor of v0.24.0 (the diff is purely additive). If you prefer to track this as a ClickHouse/v0.24.0 release branch (matching the existing ClickHouse/v0.22.0 / ClickHouse/v0.23.0 convention that the submodule pins), the branch head pushed to my fork is ClickHouse/v0.24.0 and can be used as-is. Once this lands, I'll open the contrib/thrift submodule bump in ClickHouse/ClickHouse.

@thevar1able

Copy link
Copy Markdown
Member

Ok, I'll do it.

@thevar1able

Copy link
Copy Markdown
Member

Branch ClickHouse/v0.24.0 is ready, with f95a731b6d867823de096bef2bfe0c6b1886fdcc cherry-picked.

@groeneai

Copy link
Copy Markdown
Author

Thanks for creating the ClickHouse/v0.24.0 branch. Opened the ClickHouse-side submodule bump: ClickHouse/ClickHouse#111278 — pins contrib/thrift to 13d30d6a (the branch head). Could you review? Verified _thrift and _arrow build and link against the new tree.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.