Skip to content

[C++] Incorrect vector capacity check in TDigest::TDigestImpl::Validate() #53777

Closed

Description

@ezbr

Describe the bug, including details regarding any error messages, version, and platform.

The check at https://github.com/apache/arrow/blob/main/cpp/src/arrow/util/tdigest.cc#L172:

    // check if buffer expanded
    if (tdigests_[0].capacity() > delta_ || tdigests_[1].capacity() > delta_) {
      return Status::Invalid("oversized tdigest buffer");
    }

seems meant to verify that inserting into the buffers up to the previously reserved capacity didn't cause a reallocation to a larger capacity. However, the check is assuming that std::vector::reserve uses an exact capacity reservation, which is not guaranteed (https://en.cppreference.com/cpp/container/vector/reserve). We should update or remove this check, which relies on implementation details of std::vector that are subject to change.

Motivation: I'm working on using size-returning-new in std::vector::reserve, which causes this check to fail.

(See sample fix in #52276.)

Component(s)

C++

Activity

  1. changed the title [-]Incorrect vector capacity check in TDigest::TDigestImpl::Validate()[/-] [+][C++] Incorrect vector capacity check in TDigest::TDigestImpl::Validate()[/+] on Oct 14, 2026
  2. ezbr commented on Oct 16, 2026

    @ezbr
    ContributorAuthor

    This was fixed in #52276.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions