GH-50351 : [C++] KeyValueMetadata::DeleteMany method crashes#50500
Open
dkp116 wants to merge 3 commits into
Open
GH-50351 : [C++] KeyValueMetadata::DeleteMany method crashes#50500dkp116 wants to merge 3 commits into
dkp116 wants to merge 3 commits into
Conversation
…nvalid memory address
…dress to log check failed
|
Thanks for opening a pull request! If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project. Then could you also rename the pull request title in the following format? or See also: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Investigated the two usages of
DeleteManyin the codebase to verify whether there could be an issue caused by incorrect or duplicate indexes being passed.There are two locations where
DeleteManyis called:cpp/src/arrow/c/bridge.ccDeleteMany(metadata_.extension_name_index, metadata_.extension_serialized_index)The indexes are populated while iterating through metadata keys:
Here due to the if and else if statement there is not a case where they are the same value.
cpp/src/arrow/ipc/metadata_internal.ccmetadata->DeleteMany({name_index, data_index});Here, the indexes are obtained using:
FindKeytraverses thekeys_array maintained byKeyValueMetadataand returns the index of the matching key. Since the two searched keys are different:cpp/src/arrow/extension_type.ccthe returned indexes refer to two different metadata entries.
What changes are included in this PR?
This change documents/investigates the behavior of the existing
DeleteMany, and a log is produced when DeleteMany is accessing an invalid memory address instead of throwing with this error:/usr/include/c++/16.1.1/bits/stl_vector.h:1253: constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator [with _Tp = std::__cxx11::basic_string; _Alloc = std::allocator<std::__cxx11::basic_string >;
reference = std::__cxx11::basic_string&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Note: I have not prevented the use of the same index in DeleteMany as for example DeleteMany(1,1) will still give an output, given a valid key and array vector so no functionality has been changed, just a more readable log has been added.
Are these changes tested?
A test has been added to
cpp/src/arrow/util/key_value_metadata_test.ccwhich checks to see the correct error is shown when an invalid memory address is being accessedAre there any user-facing changes?
No user-facing changes.
KeyValueMetadata::DeleteManymethod crashes with duplicate0indexes #50351