GH-49752: [C++][Gandiva] Fix potential buffer overrun in gandiva ssl function#49780
Open
lriggs wants to merge 7 commits intoapache:mainfrom
Open
GH-49752: [C++][Gandiva] Fix potential buffer overrun in gandiva ssl function#49780lriggs wants to merge 7 commits intoapache:mainfrom
lriggs wants to merge 7 commits intoapache:mainfrom
Conversation
dmitry-chirkov-dremio
approved these changes
Apr 17, 2026
kou
reviewed
Apr 18, 2026
There was a problem hiding this comment.
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
snprintfsizing 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.
| File | Description |
|---|---|
cpp/src/gandiva/hash_utils_test.cc |
Adds an OpenSSL header include in the hash utils unit tests. |
cpp/src/gandiva/hash_utils.h |
Removes GANDIVA_EXPORT from gdv_hash_using_openssl declaration. |
cpp/src/gandiva/hash_utils.cc |
Fixes validation condition and tightens result buffer allocation / snprintf bounds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.