datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Window constructors panic when the expression list is empty

Open geoHeil opened this issue 3 weeks ago • 3 comments

Describe the bug

WindowAggExec::try_new and BoundedWindowAggExec::try_new index window_expr[0] when the list is empty. Both constructors return Result, but this input panics instead of returning an error.

The physical plan decoder reaches these constructors when a WindowAggExecNode contains a valid child and no window_expr entries. With panic = "abort", decoding that node stops the process.

To reproduce

use std::sync::Arc;
use arrow::datatypes::Schema;
use datafusion_physical_plan::empty::EmptyExec;
use datafusion_physical_plan::windows::{BoundedWindowAggExec, WindowAggExec};
use datafusion_physical_plan::InputOrderMode;

let input = Arc::new(EmptyExec::new(Arc::new(Schema::empty())));
WindowAggExec::try_new(vec![], input.clone(), false); // panics
BoundedWindowAggExec::try_new(vec![], input, InputOrderMode::Linear, false); // panics

The first panic was found in a peer-plan fuzz run using DataFusion 55.1.0: https://github.com/telekom/sutura/actions/runs/42873920210/job/130032073633

The unchanged input is 21 bytes, base64 ehMKBhoECgAQARoEEgKgARgUUIBA. The failure is index out of bounds: the len is 0 but the index is 0 in windows/window_agg_exec.rs. The current upstream source also has the unchecked first-element reads in both constructors; I have not run the reproducer on upstream main.

Expected behavior

Return DataFusionError::Plan when there is no window expression, before deriving the schema or partition properties. Nonempty window plans keep their current behavior.

Additional context

We are preparing a small vendored fix and worker-decode regression tests in sutura. This report is limited to the empty expression list. It does not establish that every malformed physical plan is refused.

AI assistance was used to investigate and draft this report.

geoHeil avatar Nov 10 '26 19:11 geoHeil

The vendored fix and worker-decode tests are in https://github.com/telekom/sutura/pull/1867.

A hosted replay now checks the unchanged 21-byte input against both versions: https://github.com/telekom/sutura/actions/runs/42883840932/job/130066849710. With the original constructors, the input panics at the same first-element read. With the fix, the input returns without a panic, and every retained peer-stage seed passes. The input SHA256 is checked before and after: 13c0181b8c2a4fd334aef37df4d9696c00eeec9d300c7facf089d85c392ff14d.

The fix uses window_expr.first().ok_or_else(...) in each constructor and returns DataFusionError::Plan when the list is empty. The bounded constructor reuses that checked expression for its partition properties. This replay is limited to retained inputs; it is not a new fuzz search or a complete malformed-plan audit.

geoHeil avatar Nov 10 '26 21:11 geoHeil

I'll defer this for now and leave it for someone else; I won't open a PR.

vinycalves avatar Nov 12 '26 14:11 vinycalves

take

abp002 avatar Nov 14 '26 14:11 abp002