Skip to content

GH-49973: [C++] Cover Gandiva string length regression cases - #49984

Open
puneetdixit200 wants to merge 3 commits into
apache:mainfrom
puneetdixit200:gh-49973-gandiva-string-lengths
Open

puneetdixit200 wants to merge 3 commits into
apache:mainfrom
puneetdixit200:gh-49973-gandiva-string-lengths

Conversation

@puneetdixit200

@puneetdixit200 puneetdixit200 commented May 18, 2026 •

Copy link
Copy Markdown

Rationale

Current main already handles the overflow and negative-length cases reported in GH-49973. This PR adds the remaining regression coverage and preserves the upstream implementation.

What changed

  • Exercise the quote_utf8 boundary where doubling the input length fits in int32_t, but adding the two quotes overflows.
  • Check that concat_ws rejects negative lengths in either valid word and rejects a negative separator length, including when all words are null.
  • Verify that null words ignore their lengths and a null separator returns null without inspecting input lengths.

Verification

  • Four focused GoogleTest cases passed under AddressSanitizer and UndefinedBehaviorSanitizer in a standalone harness using the production function and test bodies, with context and allocator adapters. This is not the full Gandiva test binary.
  • Reintroducing the old negative-length handling caused an AddressSanitizer failure; bypassing the quote addition check caused the boundary test to fail.
  • Changed lines formatted with clang-format 18.1.8.
  • git diff --check origin/main...HEAD passed.

The full Arrow/Gandiva build was not run locally. CI results for the refreshed commit are pending.

GitHub Issue: #49973

AI assistance disclosure

AI assistance was used to inspect the issue, reconcile the branch with current main, add regression tests, run focused validation, and prepare the PR update.

Copilot AI 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.

Pull request overview

This PR addresses remaining Gandiva string length safety issues (GH-49973) by preventing signed integer overflow during output-size computation and by rejecting negative “valid” input lengths before allocation/copy, with focused regression tests to prevent reintroduction.

Changes:

  • Fix potential signed overflow in quote_utf8 and to_hex_binary by using MultiplyWithOverflow before AddWithOverflow for allocation sizing.
  • Add explicit negative-length validation and overflow-safe length accumulation for concat_ws_* before allocation/memcpy.
  • Add regression tests covering overflow sizing and negative-length handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cpp/src/gandiva/precompiled/string_ops.cc Adds checked arithmetic for allocation sizing and validates negative lengths in concat_ws to prevent unsafe allocation/copy paths.
cpp/src/gandiva/precompiled/string_ops_test.cc Adds targeted tests asserting correct error behavior for overflow sizing and negative-length inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@puneetdixit200
puneetdixit200 force-pushed the gh-49973-gandiva-string-lengths branch from 04db88c to ad94613 Compare May 24, 2026 15:19
@puneetdixit200

Copy link
Copy Markdown
Author

Rebased this branch on current main (7c9d88028). No code changes beyond the rebase.

Verified locally:

  • git diff --check upstream/main...HEAD

Copilot AI balanced review requested due to automatic review settings October 26, 2026 13:16

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@puneetdixit200 puneetdixit200 changed the title GH-49973: [C++] Fix Gandiva string length checks GH-49973: [C++] Cover Gandiva string length regression cases Oct 26, 2026
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.

2 participants