diff --git a/parquet/src/schema/types.rs b/parquet/src/schema/types.rs index 2c63da74df47..0d504e16fc28 100644 --- a/parquet/src/schema/types.rs +++ b/parquet/src/schema/types.rs @@ -1401,7 +1401,7 @@ fn schema_from_array_helper<'a>( Some(n) => { let repetition = element.repetition_type; - let mut fields = Vec::with_capacity(n as usize); + let mut fields = Vec::with_capacity(usize::try_from(n)?); let mut next_index = index + 1; for _ in 0..n { let child_result = schema_from_array_helper(elements, num_elements, next_index)?; @@ -2517,4 +2517,22 @@ mod tests { let result_schema = parquet_schema_from_array(thrift_schema).unwrap(); assert_eq!(result_schema, expected_schema); } + + #[test] + fn test_parquet_schema_from_array_rejects_negative_num_children() { + let elements = vec![SchemaElement { + r#type: None, + type_length: None, + repetition_type: Some(Repetition::REQUIRED), + name: "schema", + num_children: Some(-1), + converted_type: None, + scale: None, + precision: None, + field_id: None, + logical_type: None, + }]; + let result = parquet_schema_from_array(elements); + assert!(result.unwrap_err().to_string().contains("Integer overflow")); + } }