From cb12feed8fbe44deea2080669f0186035859a9f6 Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Wed, 7 Oct 2026 19:34:51 +0000 Subject: [PATCH 1/2] MINOR: [C++] Check size() instead of capacity() in TDigest::TDigestImpl::Validate() `std::vector::reserve(delta_)` only guarantees `capacity() >= delta_`, not `capacity() == delta_`. When the standard library/allocator uses size-returning allocations (such as C++23 `allocate_at_least`), `reserve(delta_)` can immediately set `capacity() > delta_`, causing `TDigestImpl::Validate()` to fail with "oversized tdigest buffer" even when the number of centroids is at most `delta_`. Check `size() > delta_` instead of `capacity() > delta_` to verify that the tdigest buffer did not expand past `delta_` elements. --- cpp/src/arrow/util/tdigest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/util/tdigest.cc b/cpp/src/arrow/util/tdigest.cc index 36a83fb336d3..678b0892ef33 100644 --- a/cpp/src/arrow/util/tdigest.cc +++ b/cpp/src/arrow/util/tdigest.cc @@ -169,7 +169,7 @@ class TDigest::TDigestImpl { return Status::Invalid("tdigest total weight mismatch"); } // check if buffer expanded - if (tdigests_[0].capacity() > delta_ || tdigests_[1].capacity() > delta_) { + if (tdigests_[0].size() > delta_ || tdigests_[1].size() > delta_) { return Status::Invalid("oversized tdigest buffer"); } // check k-size From d95e57c50597d7504b7e5d9bfc3cc65f551b5081 Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Fri, 9 Oct 2026 22:06:42 +0000 Subject: [PATCH 2/2] Update comment in TDigestImpl::Validate() --- cpp/src/arrow/util/tdigest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/util/tdigest.cc b/cpp/src/arrow/util/tdigest.cc index 678b0892ef33..b8e96b5f3fe9 100644 --- a/cpp/src/arrow/util/tdigest.cc +++ b/cpp/src/arrow/util/tdigest.cc @@ -168,7 +168,7 @@ class TDigest::TDigestImpl { if (total_weight != total_weight_) { return Status::Invalid("tdigest total weight mismatch"); } - // check if buffer expanded + // check if buffer size exceeded delta if (tdigests_[0].size() > delta_ || tdigests_[1].size() > delta_) { return Status::Invalid("oversized tdigest buffer"); }