GH-50351: [C++] Fix KeyValueMetadata::DeleteMany crash with duplicate indices#50353
Closed
AdvancedUno wants to merge 1 commit into
Closed
GH-50351: [C++] Fix KeyValueMetadata::DeleteMany crash with duplicate indices#50353AdvancedUno wants to merge 1 commit into
AdvancedUno wants to merge 1 commit into
Conversation
…licate indices Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
KeyValueMetadata::DeleteManycrashes (out-of-bounds write) when the indices vectorcontains duplicates, e.g.
DeleteMany({0, 0}). The compaction loop increments itsshiftcounter once per entry, so duplicates cause writes at negative offsets.
Additionally, out-of-range indices were only checked by
DCHECK, so in release buildsDeleteMany({size})silently deleted the last element and negative indices were UB.What changes are included in this PR?
DeleteManynow validates indices after sorting and returnsStatus::IndexErrorforany index out of
[0, size), matching the behavior and message format ofDelete.Metadata is left unmodified on error.
std::uniquebefore compaction, so deleting thesame index twice is equivalent to deleting it once.
Are these changes tested?
Yes — added cases to
KeyValueMetadataTest.Deletecovering duplicate indices(
{0,0},{1,3,1,3,1}), out-of-bounds positive and negative indices (exact errormessages), and that metadata is unchanged after a failed call.
Are there any user-facing changes?
Yes, minor behavioral fix:
DeleteManynow returnsIndexErrorfor out-of-range indicesinstead of crashing (duplicates) or silently corrupting state (release builds). No API change.
KeyValueMetadata::DeleteManymethod crashes with duplicate0indexes #50351