Skip to content

ORCA: Fix use-after-free in CXformSplitWindowFunc#1853

Open
zhangwenchao-123 wants to merge 1 commit into
apache:mainfrom
zhangwenchao-123:fix_split_windowagg
Open

ORCA: Fix use-after-free in CXformSplitWindowFunc#1853
zhangwenchao-123 wants to merge 1 commit into
apache:mainfrom
zhangwenchao-123:fix_split_windowagg

Conversation

@zhangwenchao-123

Copy link
Copy Markdown
Contributor

CXformSplitWindowFunc::Transform() builds a local and a global CLogicalSequenceProject, and each constructor takes ownership of one reference to the window's distribution spec (pds), order specs (pdrgpos) and frames (pdrgpwf). Only a single AddRef() was issued for each object, so once both SequenceProjects and the original are released the reference count underflows and the objects are freed while still in use.

The dangling memory later surfaces as a corrupt (unaligned) scalar DXL node while translating a table scan filter, crashing the coordinator with SIGSEGV at CTranslatorDXLToScalar.cpp:111 during DXL-to-PlStmt translation. This reproduces on window-function queries (e.g. TPC-DS query 44) when optimizer_force_split_window_function is on; the transform is only enabled under that GUC, which is why the crash disappears when it is off.

Add the missing AddRef() for pds, pdrgpos and pdrgpwf before building the global SequenceProject, and for the Select operator and its scalar comparison before reusing them in the global Select, so every owner holds its own reference.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


CXformSplitWindowFunc::Transform() builds a local and a global
CLogicalSequenceProject, and each constructor takes ownership of one
reference to the window's distribution spec (pds), order specs
(pdrgpos) and frames (pdrgpwf). Only a single AddRef() was issued for
each object, so once both SequenceProjects and the original are
released the reference count underflows and the objects are freed
while still in use.

The dangling memory later surfaces as a corrupt (unaligned) scalar
DXL node while translating a table scan filter, crashing the
coordinator with SIGSEGV at CTranslatorDXLToScalar.cpp:111 during
DXL-to-PlStmt translation. This reproduces on window-function queries
(e.g. TPC-DS query 44) when optimizer_force_split_window_function is
on; the transform is only enabled under that GUC, which is why the
crash disappears when it is off.

Add the missing AddRef() for pds, pdrgpos and pdrgpwf before building
the global SequenceProject, and for the Select operator and its scalar
comparison before reusing them in the global Select, so every owner
holds its own reference.
@zhangwenchao-123 zhangwenchao-123 changed the title Fix use-after-free in CXformSplitWindowFunc ORCA: Fix use-after-free in CXformSplitWindowFunc Jul 15, 2026

@my-ship-it my-ship-it left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants