v.21.7Bug Fix

Fix potential crash in aggregate function calculations

Fix potential crash when calculating aggregate function states by aggregation of aggregate function states of other aggregate functions (not a practical use case). See #24523. #25015 (alexey-milovidov).