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

Method ValidateBinaryView

cpp/src/arrow/array/validate.cc:630–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628 }
629
630 Status ValidateBinaryView(const BinaryViewType& type) {
631 int64_t views_byte_size = data.buffers[1]->size();
632 int64_t required_view_count = data.length + data.offset;
633 if (static_cast<int64_t>(views_byte_size / BinaryViewType::kSize) <
634 required_view_count) {
635 return Status::Invalid("View buffer size (bytes): ", views_byte_size,
636 " isn't large enough for length: ", data.length,
637 " and offset: ", data.offset);
638 }
639
640 if (!full_validation) return Status::OK();
641
642 auto CheckPrefix = [&](size_t i,
643 std::array<uint8_t, BinaryViewType::kPrefixSize> prefix,
644 const uint8_t* data) {
645 if (std::memcmp(data, prefix.data(), BinaryViewType::kPrefixSize) == 0) {
646 return Status::OK();
647 }
648 return Status::Invalid("View at slot ", i, " has inlined prefix 0x",
649 HexEncode(prefix.data(), BinaryViewType::kPrefixSize),
650 " but the out-of-line data begins with 0x",
651 HexEncode(data, BinaryViewType::kPrefixSize));
652 };
653
654 std::span views(data.GetValues<BinaryViewType::c_type>(1),
655 static_cast<size_t>(data.length));
656 std::span data_buffers(data.buffers.data() + 2, data.buffers.size() - 2);
657
658 for (size_t i = 0; i < static_cast<size_t>(data.length); ++i) {
659 if (data.IsNull(i)) continue;
660
661 if (views[i].size() < 0) {
662 return Status::Invalid("View at slot ", i, " has negative size ",
663 views[i].size());
664 }
665
666 if (views[i].is_inline()) {
667 auto padding_bytes = std::span(views[i].inlined.data).subspan(views[i].size());
668 for (auto padding_byte : padding_bytes) {
669 if (padding_byte != 0) {
670 return Status::Invalid("View at slot ", i, " was inline with size ",
671 views[i].size(),
672 " but its padding bytes were not all zero: ",
673 HexEncode(padding_bytes.data(), padding_bytes.size()));
674 }
675 }
676 continue;
677 }
678
679 auto [size, prefix, buffer_index, offset] = views[i].ref;
680
681 if (buffer_index < 0) {
682 return Status::Invalid("View at slot ", i, " has negative buffer index ",
683 buffer_index);
684 }
685
686 if (offset < 0) {
687 return Status::Invalid("View at slot ", i, " has negative offset ", offset);

Callers

nothing calls this directly

Calls 7

HexEncodeFunction · 0.85
IndexErrorFunction · 0.85
InvalidFunction · 0.50
OKFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
IsNullMethod · 0.45

Tested by

no test coverage detected