GH-49104: [C++] Fix Segfault in SparseCSFIndex::Equals with mismatched dimensions #49105
+48
−1
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
The
SparseCSFIndex::Equalsmethod can crash when comparing two sparse indices that have a different number of dimensions. The method iterates over theindices()andindptr()vectors of the current object and accesses the corresponding elements in theotherobject without first verifying that both objects have matching vector sizes. This can lead to out-of-bounds access and a segmentation fault when the dimension counts differ.What Changes Are Included in This PR?
This change adds explicit size equality checks for the
indices()andindptr()vectors at the beginning of theSparseCSFIndex::Equalsmethod. If the dimensions do not match, the method now safely returnsfalseinstead of attempting invalid memory access.Are These Changes Tested?
Yes. The fix has been validated through targeted reproduction of the crash scenario using mismatched dimension counts, ensuring the method behaves safely and deterministically.
Are There Any User-Facing Changes?
No. This change improves internal safety and robustness without altering public APIs or observable user behavior.
Closes
Closes #49104
GitHub Issue: [C++] Segfault in SparseCSFIndex::Equals with mismatched dimensions #49104