Skip to content

Commit 32730a9

Browse files
committed
fix: add field count validation in AVRO_RECORD encoding
Validate that the number of fields matches between Arrow struct array, Iceberg struct type, and Avro node before iterating to prevent out-of-bounds access. - Check struct_array.num_fields() matches avro_node->leaves() - Check struct_type.fields().size() matches avro_node->leaves() - Return InvalidArgument error with clear message on mismatch
1 parent cc007f7 commit 32730a9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/iceberg/avro/avro_direct_encoder.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ Status EncodeArrowToAvro(const ::avro::NodePtr& avro_node, ::avro::Encoder& enco
245245
const auto& struct_type = static_cast<const StructType&>(type);
246246
const size_t num_fields = avro_node->leaves();
247247

248+
// Validate field count matches
249+
if (struct_array.num_fields() != static_cast<int>(num_fields)) {
250+
return InvalidArgument(
251+
"Field count mismatch: Arrow struct has {} fields, Avro node has {} fields",
252+
struct_array.num_fields(), num_fields);
253+
}
254+
if (struct_type.fields().size() != num_fields) {
255+
return InvalidArgument(
256+
"Field count mismatch: Iceberg struct has {} fields, Avro node has {} fields",
257+
struct_type.fields().size(), num_fields);
258+
}
259+
248260
for (size_t i = 0; i < num_fields; ++i) {
249261
const auto& field_node = avro_node->leafAt(i);
250262
const auto& field_array = struct_array.field(static_cast<int>(i));

0 commit comments

Comments
 (0)