Skip to content

GH-49752: [C++][Gandiva] Fix potential buffer overrun in Gandiva SSL function - #49780

Merged
kou merged 12 commits into
apache:mainfrom
lriggs:GH-49752
Jun 2, 2026
Merged

GH-49752: [C++][Gandiva] Fix potential buffer overrun in Gandiva SSL function#49780
kou merged 12 commits into
apache:mainfrom
lriggs:GH-49752

Conversation

@lriggs

@lriggslriggs commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

Fixes security related problems found in gdv_hash_using_openssl. Those problems were not deemed to be a security risk.

What changes are included in this PR?

[hash_utils.h:41, hash_utils.cc:66] Removed GANDIVA_EXPORT from gdv_hash_using_openssl — it's an internal helper, not part of the public API.

[hash_utils.cc:105] Changed && → || in the validation condition. The original only errored when both checks failed; now it errors when either result_length != hash_digest_size or result_buf_size != (2 * hash_digest_size).

[hash_utils.cc:135] Fixed snprintf buffer size, so it correctly accounts for the already-written bytes and prevents potential out-of-bounds writes. Allocate result_buf_size + 1 bytes — the extra byte absorbs the final null terminator. Pass result_buf_size - result_buff_index + 1 to snprintf — reflects the actual remaining space (2 hex chars + 1 null = 3 bytes on the last call), preventing any potential overflow if the format ever changed.

Are these changes tested?

Yes, unit tests.

Are there any user-facing changes?

No.

Comment threadcpp/src/gandiva/hash_utils_test.cc Outdated
@github-actionsgithub-actionsBot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Apr 16, 2026
@koukou changed the title GH-49752: Fix potential buffer overrun in gandiva ssl function.GH-49752: [C++][Gandiva] Fix potential buffer overrun in gandiva ssl functionApr 18, 2026
@kou
kou requested a review from CopilotApril 18, 2026 09:13
Comment threadcpp/src/gandiva/hash_utils_test.cc Outdated
Comment threadcpp/src/gandiva/hash_utils.cc
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Apr 18, 2026

CopilotAI 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 correctness/safety issues in Gandiva’s OpenSSL-based hashing helper (gdv_hash_using_openssl) and reduces its intended API exposure.

Changes:

  • Stops exporting gdv_hash_using_openssl (intended to be internal).
  • Fixes validation logic so mismatched digest size or result buffer size triggers an error.
  • Adjusts result-buffer allocation and snprintf sizing to avoid potential out-of-bounds writes when hex-encoding the digest.

Reviewed changes

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

FileDescription
cpp/src/gandiva/hash_utils_test.ccAdds an OpenSSL header include in the hash utils unit tests.
cpp/src/gandiva/hash_utils.hRemoves GANDIVA_EXPORT from gdv_hash_using_openssl declaration.
cpp/src/gandiva/hash_utils.ccFixes validation condition and tightens result buffer allocation / snprintf bounds.

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

Comment threadcpp/src/gandiva/hash_utils.h Outdated
Comment threadcpp/src/gandiva/hash_utils.cc
Comment threadcpp/src/gandiva/hash_utils_test.cc Outdated
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Apr 18, 2026
Comment threadcpp/src/gandiva/hash_utils.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Apr 20, 2026
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Apr 20, 2026
@lriggs
lriggs requested a review from kouMay 1, 2026 17:47
@kou
kou requested a review from CopilotMay 1, 2026 21:42

CopilotAI 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

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


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

Comment threadcpp/src/gandiva/hash_utils.h
Comment threadcpp/src/gandiva/hash_utils.cc Outdated
@lriggs

Copy link
Copy Markdown
ContributorAuthor

@kou I think this is ready for review. Im not sure why its labelled awaiting change, I think I addressed and resolved them all.

@koukou changed the title GH-49752: [C++][Gandiva] Fix potential buffer overrun in gandiva ssl functionGH-49752: [C++][Gandiva] Fix potential buffer overrun in Gandiva SSL functionJun 2, 2026
kou
kou approved these changes Jun 2, 2026

@koukou 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 d586ed1 into apache:mainJun 2, 2026
53 checks passed
@koukou removed the awaiting change review Awaiting change review label Jun 2, 2026
@github-actionsgithub-actionsBot added the awaiting merge Awaiting merge label Jun 2, 2026
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit d586ed1.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 4 possible false positives for unstable benchmarks that are known to sometimes produce them.

@lriggs
lriggs deleted the GH-49752 branch June 4, 2026 16:52
Sign up for freeto 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.

4 participants

@lriggs@kou@dmitry-chirkov-dremio