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

Method ValidateLayout

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

Source from the content-addressed store, hash-verified

471 }
472
473 Status ValidateLayout(const DataType& type) {
474 // Check the data layout conforms to the spec
475 const auto layout = type.layout();
476
477 if (data.length < 0) {
478 return Status::Invalid("Array length is negative");
479 }
480
481 if (layout.variadic_spec) {
482 if (data.buffers.size() < layout.buffers.size()) {
483 return Status::Invalid("Expected at least ", layout.buffers.size(),
484 " buffers in array of type ", type.ToString(), ", got ",
485 data.buffers.size());
486 }
487 } else if (data.buffers.size() != layout.buffers.size()) {
488 return Status::Invalid("Expected ", layout.buffers.size(),
489 " buffers in array of type ", type.ToString(), ", got ",
490 data.buffers.size());
491 }
492
493 // This check is required to avoid addition overflow below
494 int64_t length_plus_offset = -1;
495 if (AddWithOverflow(data.length, data.offset, &length_plus_offset)) {
496 return Status::Invalid("Array of type ", type.ToString(),
497 " has impossibly large length and offset");
498 }
499
500 for (int i = 0; i < static_cast<int>(data.buffers.size()); ++i) {
501 const auto& buffer = data.buffers[i];
502 const auto& spec = i < static_cast<int>(layout.buffers.size())
503 ? layout.buffers[i]
504 : *layout.variadic_spec;
505
506 if (buffer == nullptr) {
507 if (layout.variadic_spec && i >= static_cast<int>(layout.buffers.size())) {
508 return Status::Invalid("Array of type ", type.ToString(),
509 " has a null variadic buffer at buffer index #", i,
510 " (variadic buffer index #", i - layout.buffers.size(),
511 ")");
512 }
513 continue;
514 }
515 int64_t min_buffer_size = 0;
516 switch (spec.kind) {
517 case DataTypeLayout::BITMAP:
518 // If length == 0, buffer size can be 0 regardless of offset
519 if (data.length > 0) {
520 min_buffer_size = bit_util::BytesForBits(length_plus_offset);
521 }
522 break;
523 case DataTypeLayout::FIXED_WIDTH:
524 if (data.length > 0 && MultiplyWithOverflow(length_plus_offset, spec.byte_width,
525 &min_buffer_size)) {
526 return Status::Invalid("Array of type ", type.ToString(),
527 " has impossibly large length and offset");
528 }
529 break;
530 case DataTypeLayout::ALWAYS_NULL:

Callers

nothing calls this directly

Calls 8

AddWithOverflowFunction · 0.85
BytesForBitsFunction · 0.85
MultiplyWithOverflowFunction · 0.85
InvalidFunction · 0.50
OKFunction · 0.50
layoutMethod · 0.45
sizeMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected