Skip to content

Fix index oob panic in unparser with mismatched stacked projections#21094

Open
friendlymatthew wants to merge 1 commit intoapache:mainfrom
pydantic:friendlymatthew/fix-unparser-stacked-projection-check
Open

Fix index oob panic in unparser with mismatched stacked projections#21094
friendlymatthew wants to merge 1 commit intoapache:mainfrom
pydantic:friendlymatthew/fix-unparser-stacked-projection-check

Conversation

@friendlymatthew
Copy link
Contributor

Rationale for this change

This PR adds a length guard in subquery_alias_inner_query_and_columns to prevent a panic when outer and inner projections have different expression counts

Without this fix, optimizer passes like CommonSubexprEliminate can produce stacked projections where the inner projections has more exprs than the outer. The function iterates over inner_projection.expr by index and uses the same index to access outer_projections.expr, causing an index oob panic

This PR bails out early when the lengths don't match. This is consistent with all the other early returns in the function that reject non-matching plan shapes

@github-actions github-actions bot added the sql SQL Planner label Mar 21, 2026
Copy link
Contributor Author

@friendlymatthew friendlymatthew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

Comment on lines +313 to +316
if outer_projections.expr.len() != inner_projection.expr.len() {
return (plan, vec![]);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can confirm that when I remove this, the test below will panic

Copy link
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 this fixes a runtime panic (very bad) and causes no other test regressions

@friendlymatthew friendlymatthew force-pushed the friendlymatthew/fix-unparser-stacked-projection-check branch from 1ccec81 to 1ae3bd2 Compare March 21, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants