From 9e54dcaa5b52dbb090a1568305478770eecd6137 Mon Sep 17 00:00:00 2001 From: Tai Le Manh Date: Thu, 15 Aug 2024 22:14:43 +0700 Subject: [PATCH 1/2] Handle arguments checking of min/max function to avoid crashes Signed-off-by: Tai Le Manh --- datafusion/functions-aggregate/src/min_max.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/datafusion/functions-aggregate/src/min_max.rs b/datafusion/functions-aggregate/src/min_max.rs index f9a08631bfb9..c865ffcecd0d 100644 --- a/datafusion/functions-aggregate/src/min_max.rs +++ b/datafusion/functions-aggregate/src/min_max.rs @@ -48,7 +48,7 @@ use arrow::datatypes::{ Int32Type, Int64Type, Int8Type, UInt16Type, UInt32Type, UInt64Type, UInt8Type, }; use arrow_schema::IntervalUnit; -use datafusion_common::{downcast_value, internal_err, DataFusionError, Result}; +use datafusion_common::{downcast_value, exec_err, internal_err, DataFusionError, Result}; use datafusion_functions_aggregate_common::aggregate::groups_accumulator::prim_op::PrimitiveGroupsAccumulator; use std::fmt::Debug; @@ -68,7 +68,12 @@ use std::ops::Deref; fn get_min_max_result_type(input_types: &[DataType]) -> Result> { // make sure that the input types only has one element. - assert_eq!(input_types.len(), 1); + if input_types.len() != 1 { + return exec_err!( + "min/max was called with {} arguments. It requires only 1.", + input_types.len() + ) + } // min and max support the dictionary data type // unpack the dictionary to get the value match &input_types[0] { From ec919d825498ae724a387902092135f42b33e76c Mon Sep 17 00:00:00 2001 From: Tai Le Manh Date: Thu, 15 Aug 2024 22:47:08 +0700 Subject: [PATCH 2/2] Fix code format error --- datafusion/functions-aggregate/src/min_max.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/datafusion/functions-aggregate/src/min_max.rs b/datafusion/functions-aggregate/src/min_max.rs index c865ffcecd0d..4dcd5ac0e951 100644 --- a/datafusion/functions-aggregate/src/min_max.rs +++ b/datafusion/functions-aggregate/src/min_max.rs @@ -48,7 +48,9 @@ use arrow::datatypes::{ Int32Type, Int64Type, Int8Type, UInt16Type, UInt32Type, UInt64Type, UInt8Type, }; use arrow_schema::IntervalUnit; -use datafusion_common::{downcast_value, exec_err, internal_err, DataFusionError, Result}; +use datafusion_common::{ + downcast_value, exec_err, internal_err, DataFusionError, Result, +}; use datafusion_functions_aggregate_common::aggregate::groups_accumulator::prim_op::PrimitiveGroupsAccumulator; use std::fmt::Debug; @@ -72,7 +74,7 @@ fn get_min_max_result_type(input_types: &[DataType]) -> Result> { return exec_err!( "min/max was called with {} arguments. It requires only 1.", input_types.len() - ) + ); } // min and max support the dictionary data type // unpack the dictionary to get the value