MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/arrow/ipc/tensor_test.cc:585–661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

583} // namespace
584
585TEST(TestSparseCSFIndex, RejectInconsistentBufferCounts) {
586 ARROW_SUPPRESS_DEPRECATION_WARNING
587 // ndim == 1 is not a valid CSF index (it has no indptr buffers), and used to
588 // reach SparseCSFIndex's constructor with an empty indptr vector.
589 ASSERT_OK_AND_ASSIGN(auto message,
590 MakeCSFSparseTensorMessage(/*shape=*/{4}, /*num_indptr_buffers=*/0,
591 /*num_indices_buffers=*/1,
592 /*axis_order_size=*/1));
593 ASSERT_RAISES(Invalid, ReadSparseTensor(*message));
594
595 // Too many indices buffers for the declared number of dimensions, which used
596 // to write past the end of the fixed-size index vectors.
597 ASSERT_OK_AND_ASSIGN(
598 message, MakeCSFSparseTensorMessage(/*shape=*/{4, 4}, /*num_indptr_buffers=*/1,
599 /*num_indices_buffers=*/3,
600 /*axis_order_size=*/2));
601 ASSERT_RAISES(Invalid, ReadSparseTensor(*message));
602
603 // axisOrder and indicesBuffers lengths disagree (out-of-bounds read).
604 ASSERT_OK_AND_ASSIGN(
605 message, MakeCSFSparseTensorMessage(/*shape=*/{4, 4}, /*num_indptr_buffers=*/1,
606 /*num_indices_buffers=*/2,
607 /*axis_order_size=*/3));
608 ASSERT_RAISES(Invalid, ReadSparseTensor(*message));
609 ARROW_UNSUPPRESS_DEPRECATION_WARNING
610}
611
612TEST(TestSparseCSFIndex, RejectInconsistentPayloadBufferCounts) {
613 ARROW_SUPPRESS_DEPRECATION_WARNING
614 ASSERT_OK_AND_ASSIGN(auto message,
615 MakeCSFSparseTensorMessage(/*shape=*/{4}, /*num_indptr_buffers=*/0,
616 /*num_indices_buffers=*/1,
617 /*axis_order_size=*/1));
618 ASSERT_RAISES(Invalid,
619 internal::ReadSparseTensorPayload(MakeSparseTensorPayload(message, 2)));
620
621 ASSERT_OK_AND_ASSIGN(
622 message, MakeCSFSparseTensorMessage(/*shape=*/{4, 4}, /*num_indptr_buffers=*/1,
623 /*num_indices_buffers=*/3,
624 /*axis_order_size=*/3));
625 ASSERT_RAISES(Invalid,
626 internal::ReadSparseTensorPayload(MakeSparseTensorPayload(message, 4)));
627 ARROW_UNSUPPRESS_DEPRECATION_WARNING
628}
629
630TEST(TestSparseCSXIndex, RejectIndptrLengthOverflow) {
631 auto empty = Buffer::FromString("");
632 ASSERT_RAISES(Invalid,
633 SparseCSRIndex::Make(int64(), {std::numeric_limits<int64_t>::max(), 1},
634 /*non_zero_length=*/0, empty, empty));
635 ASSERT_RAISES(Invalid,
636 SparseCSCIndex::Make(int64(), {1, std::numeric_limits<int64_t>::max()},
637 /*non_zero_length=*/0, empty, empty));
638}
639
640TEST(TestSparseTensor, RejectNegativeShapeAndNonZeroLength) {
641 // A negative non_zero_length must be rejected by GetSparseTensorMetadata,
642 // otherwise the negative size product bypasses the index buffer-size guards.

Callers

nothing calls this directly

Calls 7

ReadSparseTensorFunction · 0.85
ReadSparseTensorPayloadFunction · 0.85
MakeSparseTensorPayloadFunction · 0.85
FromStringFunction · 0.85
ASSERT_OK_AND_ASSIGNFunction · 0.50
MakeFunction · 0.50

Tested by

no test coverage detected