Repository navigation
Conversation
473cec3 to
83eba91
Compare
|
@pitrou here's a proposal for several sparse index checkers. |
There was a problem hiding this comment.
🟡 Changes recommended
Sparse tensor validation can read past the buffer because the index and indptr helpers assume packed storage without rejecting non-contiguous vectors.
1 open issue
What changed in this PR
This PR strengthens C++ sparse tensor validation for GH-50816, rejecting malformed indices before dense conversion and correcting CSF index buffer sizing in IPC.
Changes:
- Validate index bounds, buffers, compressed pointers, axis ordering, and conversion sizes.
- Respect COO coordinate strides and encode CSF IPC buffer lengths in bytes.
- Add regression tests for malformed inputs and IPC round trips.
| File | Description |
|---|---|
| cpp/src/arrow/tensor/coo_converter.cc | Respect coordinate strides during dense conversion. |
| cpp/src/arrow/tensor.h | Declare the shared permutation validator. |
| cpp/src/arrow/tensor.cc | Implement the shared permutation validator. |
| cpp/src/arrow/tensor_test.cc | Test valid and invalid permutations. |
| cpp/src/arrow/sparse_tensor.h | Declare and connect sparse index validation. |
| cpp/src/arrow/sparse_tensor.cc | Validate sparse indices, buffers, and conversion sizes. |
| cpp/src/arrow/sparse_tensor_test.cc | Add sparse validation and conversion regressions. |
| cpp/src/arrow/ipc/tensor_test.cc | Test CSF buffer sizing and invalid IPC inputs. |
| cpp/src/arrow/ipc/metadata_internal.cc | Correct CSF buffer lengths and validate layouts. |
| cpp/src/arrow/extension/tensor_internal.h | Remove the relocated validator declaration. |
| cpp/src/arrow/extension/tensor_internal.cc | Remove the relocated validator implementation. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Maintainer review is needed to clarify compatibility expectations for previously serialized CSF messages and older readers when IPC buffer lengths change from element counts to byte counts.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
pitrou
left a comment
There was a problem hiding this comment.
I honestly don't want to review all of this.
(did you write it yourself or is it from AI?)
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> |
| ARROW_ASSIGN_OR_RAISE(const int64_t size, ::arrow::internal::ComputeTensorSize( | ||
| tensor->shape(), tensor->strides(), | ||
| value_type.byte_width())); | ||
| result.emplace_back(buffers[buffer_index++].offset, size); |
There was a problem hiding this comment.
I honestly don't understand this part, so I'm going to trust you that it is right (is it properly tested?).
| ASSERT_RAISES(Invalid, ReadSparseTensor(*message)); | ||
| ARROW_UNSUPPRESS_DEPRECATION_WARNING | ||
| ASSERT_RAISES(Invalid, | ||
| internal::ReadSparseTensorPayload(MakeSparseTensorPayload(message, 4))); |
There was a problem hiding this comment.
What is 4? Would you care to make the parameter name explicit?
| ASSERT_OK(WriteSparseTensor(*tensor, sink.get(), &metadata_length, &body_length)); | ||
| ASSERT_OK_AND_ASSIGN(auto serialized, sink->Finish()); | ||
| io::BufferReader reader(serialized); | ||
| ASSERT_OK_AND_ASSIGN(auto result, ReadSparseTensor(&reader)); |
There was a problem hiding this comment.
Can we further validate the result here?
| std::is_same_v<IndexType, UInt8Type> || | ||
| std::is_same_v<IndexType, UInt16Type> || | ||
| std::is_same_v<IndexType, UInt32Type>) { | ||
| return visit(index_type); |
There was a problem hiding this comment.
How about is_integer(IndexType::type_id) && IndexType::type_id != Type::UINT64?
|
@rok I'll let you decide the appropriate way forward. It can involve another reviewer, or enough care and polishing on your part :-) |
460c233 to
0d22042
Compare
0d22042 to
5fa0ca9
Compare

Rationale for this change
Invalid COO, CSR, and CSC sparse tensor indices and buffers should be rejected consistently on construction, IPC read, and dense conversion. CSF validation will be handled in a follow-up PR.
What changes are included in this PR?
indptrconsistency, and backing buffers.MakeandToTensor.Makeconstructors in the CSX IPC reader.Are these changes tested?
Yes. Regression tests were added in
sparse_tensor_test.ccandipc/tensor_test.cc.Are there any user-facing changes?
Invalid COO, CSR, and CSC sparse tensor inputs that were previously accepted are now rejected with an
Invalidstatus.