GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision#50545
Open
Arawoof06 wants to merge 1 commit into
Open
GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision#50545Arawoof06 wants to merge 1 commit into
Arawoof06 wants to merge 1 commit into
Conversation
|
|
|
|
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
round_int32_int32andround_int64_int32negate the caller-supplied precision intoabs_precisionbefore range-checking it, so the checkabs_precision > 9(and> 18for the int64 overload) never fires forprecision == INT32_MIN, where the negation leaves the value negative. That value reachesget_power_of_10, which indexes a 19-element static table behindDCHECK_GE/DCHECK_LEonly. The DCHECKs compile out in release builds, soround(int_col, -2147483648)reads far outside the table and either faults or returns arbitrary memory as the rounding multiplier. Both overloads are registered infunction_registry_arithmetic.cc, so the precision comes straight from user SQL.truncate_int64_int32in the same file already compares the signed scale directly (out_scale < -38) and is unaffected; the tworoundoverloads are the only sites that negate first.What changes are included in this PR?
Check the bound against the signed
precisionbefore negating, at both sites. Every precision that was in range before still takes the same path, and the negation now only runs on values known to be within 9 (or 18) of zero.Are these changes tested?
Yes. Added two cases to
TestExtendedMathOps.TestRoundcoveringstd::numeric_limits<int32_t>::min()for both overloads, matching the existingtruncate_int64_int32case in the same file. On the unpatched tree the debug build aborts withextended_math_ops.cc:372: Check failed: (exp) >= (0); with the fix the fullgandiva-precompiled-testsuite passes (134 tests).Are there any user-facing changes?
No.
This PR contains a "Critical Fix". It fixes an out-of-bounds read reachable from a user-supplied
roundprecision argument.