You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++] KeyValueMetadata gives seg fault while deleting a key #50311
Here if the index is out of bounds, i.e. index >= keys_.size() or index < 0, then this will throw a seg fault or may corrupt memory.
The script I used for testing this
#include<arrow/util/key_value_metadata.h>
#include<iostream>using arrow::Status;
using std::cin;
using std::cout;
using std::endl;
Status reproduce_delete() {
arrow::KeyValueMetadata meta;
return meta.Delete(20);
}
voidDeleteSegFault() {
// The delete method on KeyValueMetadata
Status st = reproduce_delete(); // this seg faultsif (st.ok()) { // if no seg fault then this would be triggered, also memory// could be currupted
cout << "The bug exsits and returns a OK status even when the index to ""delete is out of range."
<< endl;
}
}
intmain() {
DeleteSegFault();
}
Would a fix like the below would be good? If so I will open a PR for it.
I also used ARROW_PREDICT_FALSE to minimise the overhead.
Status KeyValueMetadata::Delete(int64_t index) {
if (ARROW_PREDICT_FALSE(index < 0 || std::cmp_greater_equal(index, values_.size()))) {
returnarrow::Status::IndexError("Index out of bounds. Expected 0 to ", std::to_string(keys_.size() - 1), ", but got ", std::to_string(index));
}
keys_.erase(keys_.begin() + index);
values_.erase(values_.begin() + index);
returnStatus::OK();
}
std::cmp_greater_equal is a C++20 feature, as Arrow requires a minimum of C++20 compiler, I believe it's fine to use this.
changed the title [-]`KeyValueMetadata` error handling could be more robust[/-][+][C++] `KeyValueMetadata` error handling could be more robust[/+]on Jul 1, 2026
changed the title [-][C++] `KeyValueMetadata` error handling could be more robust[/-][+]`KeyValueMetadata` gives seg fault while deleting[/+]on Jul 1, 2026
changed the title [-]`KeyValueMetadata` gives seg fault while deleting a key[/-][+][C++] `KeyValueMetadata` gives seg fault while deleting a key[/+]on Jul 1, 2026
Activity
[-]`KeyValueMetadata` error handling could be more robust[/-][+][C++] `KeyValueMetadata` error handling could be more robust[/+][-][C++] `KeyValueMetadata` error handling could be more robust[/-][+]`KeyValueMetadata` gives seg fault while deleting[/+][-]`KeyValueMetadata` gives seg fault while deleting[/-][+]`KeyValueMetadata` gives seg fault while deleting a key[/+][-]`KeyValueMetadata` gives seg fault while deleting a key[/-][+][C++] `KeyValueMetadata` gives seg fault while deleting a key[/+]OmBiradar commentedon Jul 1, 2026
take
GH-50311: [C++] `KeyValueMetadata::Delete` returns IndexError instead…
pitrou commentedon Jul 2, 2026
Issue resolved by pull request 50322
#50322