Skip to content

GH-55615: [C++][Gandiva] Validate the input expression of IN - #55609

Merged
kou merged 3 commits into
apache:mainfrom
dmitry-chirkov-dremio:pr3-in-validation
Nov 27, 2026
Merged

kou merged 3 commits into
apache:mainfrom
dmitry-chirkov-dremio:pr3-in-validation

Conversation

@dmitry-chirkov-dremio

@dmitry-chirkov-dremio dmitry-chirkov-dremio commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

ExprValidator checks the value list of IN but not its input expression. An IF with an int32 condition is rejected alone and accepted under IN. A null input crashes Projector::Make with SIGSEGV.

What changes are included in this PR?

The PR has the tests first, then the fix in expr_validator.cc and node.h.

ValidateInExpression checks that the input and its type are not null, and visits the input. InExpressionNode::ToString() prints null for a null input, so the cache key does not crash before validation.

Are these changes tested?

Yes. The new tests cover invalid, null and untyped input for all IN value types, with Projector::Make and Filter::Make, and a valid IN. On main, one of them fails and two crash with SIGSEGV. All of them pass with the fix.

Are there any user-facing changes?

Make now returns ExpressionValidationError for an IN with an invalid or null input. Before, it accepted it or crashed.

This PR contains a "Critical Fix". It fixes a crash. Projector::Make and Filter::Make die with SIGSEGV (exit code 139) when the input expression of an IN node is null. The null pointer is dereferenced in InExpressionNode::ToString(), which the cache key calls before the validator runs. Both Make calls now return ExpressionValidationError.

Was AI used for this PR?

AI tools helped investigate the bug and write the fix, tests, and description.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

The tests cover an invalid, a null and an untyped input expression of IN, for Projector::Make and Filter::Make. They fail or crash on main. The fix is in the next commit.
ExprValidator checked the value list of IN but not its input expression. An invalid input was accepted and a null input crashed Make. The validator now rejects a null input or type and visits the input. InExpressionNode::ToString() prints null for a null input, so the cache key does not crash before validation.
@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

This pull request has been automatically converted to a draft because its title doesn't match Arrow's required format.

If this is not a minor PR, could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

After updating the title, you can mark the pull request as ready for review.

See also:

@dmitry-chirkov-dremio dmitry-chirkov-dremio changed the title [C++][Gandiva] Validate the input expression of IN [GH-TBD] [C++][Gandiva] Validate the input expression of IN Nov 14, 2026
@dmitry-chirkov-dremio dmitry-chirkov-dremio changed the title [GH-TBD] [C++][Gandiva] Validate the input expression of IN GH-TBD: [C++][Gandiva] Validate the input expression of IN Nov 14, 2026
@dmitry-chirkov-dremio

dmitry-chirkov-dremio commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

CI results for the new tests.

Tests-only commit, before the fix: gandiva-projector-test fails on all four C++ platforms, as predicted (ARM64 Ubuntu 22.04 LLVM 18.1.8, AMD64 Ubuntu 24.04 ASAN UBSAN LLVM 18.1.3, AMD64 macOS 15-intel LLVM 18.1.8, ARM64 macOS 26 LLVM 23.1.4). The sequence is the same everywhere:

  1. ValidationTestProjector.TestInExpressionValidatesEvalExpression fails. Make accepts an IF with an int32 condition when it is wrapped in IN.
  2. ValidationTestProjector.TestInExpressionNullEvalExpression crashes the test binary.

The crash is in InExpressionNode<int>::ToString(), node.h:254. The cache key calls it before the validator runs. The ASAN job reports member call on null pointer of type 'gandiva::Node' at the same line.

Different from what I predicted: the crash stops the binary, so TestInExpressionUntypedEvalExpression and TestInExpressionValid never ran in CI.

With the fix commit, gandiva-projector-test passes on all four platforms.

A few known failures seen previously also appeared. They are not related to this PR.

@dmitry-chirkov-dremio dmitry-chirkov-dremio changed the title GH-TBD: [C++][Gandiva] Validate the input expression of IN GH-55615: [C++][Gandiva] Validate the input expression of IN Nov 14, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55615 has been automatically assigned in GitHub to PR creator.

@dmitry-chirkov-dremio
dmitry-chirkov-dremio marked this pull request as ready for review November 14, 2026 23:04
@dmitry-chirkov-dremio

Copy link
Copy Markdown
Contributor Author

@lriggs @akravchukdremio @xxlaykxx please review

@xxlaykxx xxlaykxx 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.

🟢 Verdict: No issues found — the fix is correct and minimal, and the new tests cover both the missed validation and the crash.

What I checked

  • The null-type check is necessary, not just defensive: Visit(LiteralNode) dereferences return_type(), so without it the untyped-literal test would crash inside the validator instead of returning an error.
  • Ordering in ValidateInExpression is right: null check, then Accept, then the type comparison. The decimal specialization duplicating the call (no type() accessor) matches the pre-PR shape.
  • The "null" placeholder in ToString() cannot collide with a real expression's cache key, since field, literal and function nodes all print a type prefix or function name.

Minor, non-blocking

  • FunctionNode::ToString() already uses untyped for a missing type. Using untyped (or (null)) here instead of null would keep the cache-key vocabulary consistent and avoid confusion with Arrow's null data type name. Cosmetic only.
  • Visit(IfNode), Visit(FunctionNode) and Visit(BooleanNode) have the same pre-existing gap: they dereference children and child return types without null checks. Out of scope here, but possibly worth a follow-up issue if Make should be robust against any malformed tree.

AI-assisted analysis

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

@kou
kou merged commit 1140d8e into apache:main Nov 27, 2026
54 of 56 checks passed
@dmitry-chirkov-dremio
dmitry-chirkov-dremio deleted the pr3-in-validation branch November 28, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants