GH-49470: [C++][Gandiva] Fix crashes in substring_index and truncate with extreme integer values#49471
Open
dmitry-chirkov-dremio wants to merge 2 commits intoapache:mainfrom
Conversation
…ncate with extreme integer values
|
|
lriggs
reviewed
Mar 9, 2026
lriggs
reviewed
Mar 11, 2026
zanmato1984
approved these changes
Mar 13, 2026
lriggs
approved these changes
Mar 14, 2026
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
Two Gandiva functions crash when called with extreme integer parameter values:
substring_index(VARCHAR, VARCHAR, INT)crashes with SIGBUS when count isINT_MINtruncate(BIGINT, INT)crashes with SIGSEGV when scale isINT_MAXorINT_MINWhat changes are included in this PR?
substring_index fix (
gdv_string_function_stubs.cc):abs(cnt)with safeint64_tcomputation to avoid undefined behavior whencnt == INT_MINtruncate fix (
precompiled/extended_math_ops.cc):GetScaleMultiplierAre these changes tested?
Yes. Added coverage for
INT_MAX/INT_MINvalues ingdv_function_stubs_test.ccandextended_math_ops_test.cc.Are there any user-facing changes?
No.
This PR contains a "Critical Fix". These changes fix crashes caused by:
abs(INT_MIN)triggering undefined behavior (integer overflow) insubstring_indexGetScaleMultiplierwhentruncatereceives extreme scale values