You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "AdvancedUno (via GitHub)" <gi...@apache.org> on 2026/07/03 06:33:24 UTC

[PR] GH-50351: [C++] Fix KeyValueMetadata::DeleteMany crash with duplicate indices [arrow]

AdvancedUno opened a new pull request, #50353:
URL: https://github.com/apache/arrow/pull/50353

   ### Rationale for this change
   
   `KeyValueMetadata::DeleteMany` crashes (out-of-bounds write) when the indices vector
   contains duplicates, e.g. `DeleteMany({0, 0})`. The compaction loop increments its `shift`
   counter once per entry, so duplicates cause writes at negative offsets.
   
   Additionally, out-of-range indices were only checked by `DCHECK`, so in release builds
   `DeleteMany({size})` silently deleted the last element and negative indices were UB.
   
   ### What changes are included in this PR?
   
   - `DeleteMany` now validates indices after sorting and returns `Status::IndexError` for
     any index out of `[0, size)`, matching the behavior and message format of `Delete`.
     Metadata is left unmodified on error.
   - Duplicate indices are removed with `std::unique` before compaction, so deleting the
     same index twice is equivalent to deleting it once.
   
   ### Are these changes tested?
   
   Yes — added cases to `KeyValueMetadataTest.Delete` covering duplicate indices
   (`{0,0}`, `{1,3,1,3,1}`), out-of-bounds positive and negative indices (exact error
   messages), and that metadata is unchanged after a failed call.
   
   ### Are there any user-facing changes?
   
   Yes, minor behavioral fix: `DeleteMany` now returns `IndexError` for out-of-range indices
   instead of crashing (duplicates) or silently corrupting state (release builds). No API change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50351: [C++] Fix KeyValueMetadata::DeleteMany crash with duplicate indices [arrow]

Posted by "AdvancedUno (via GitHub)" <gi...@apache.org>.
AdvancedUno closed pull request #50353: GH-50351: [C++] Fix KeyValueMetadata::DeleteMany crash with duplicate indices
URL: https://github.com/apache/arrow/pull/50353


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org