apache / apache/arrow

[C++] `KeyValueMetadata::DeleteMany` method crashes with duplicate `0` indexes

Open
#50,351 5 comments 0 reactions 1 assignee Claimed by @AdvancedUno View on GitHub
Component: C++ Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 18h
Merged PRs (30d)
91

Description

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

When a `vector` having duplicate indexes - specifically `{0,0}` is passed to the `KeyValueMetadata::DeleteMany` method, it crashes.

It does not happen for any other numbers duplicates, rather only for `0` appearing more than once.

Script I used to test it:
```cpp
void DeleteManyBugs() {
arrow::KeyValueMetadata meta({"k1", "k2"}, {"v1", "v2"});
Status st = meta.DeleteMany({0, 0});
if (!st.ok()) {
cout << "DeleteMany failed with a error status: " << st.ToString() << endl;
}
}

int main() {
DeleteManyBugs();
}
```
Output:
```bash
/usr/include/c++/16.1.1/bits/stl_vector.h:1253: constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::__cxx11::basic_string; _Alloc = std::allocator >;
reference = std::__cxx11::basic_string&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
[2] 2089238 abort (core dumped) ./main.out
```
### Component(s)

C++

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.