You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Arawoof06 (via GitHub)" <gi...@apache.org> on 2026/07/19 08:01:13 UTC

[PR] GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision [arrow]

Arawoof06 opened a new pull request, #50545:
URL: https://github.com/apache/arrow/pull/50545

   ### Rationale for this change
   
   `round_int32_int32` and `round_int64_int32` negate the caller-supplied precision into `abs_precision` before range-checking it, so the check `abs_precision > 9` (and `> 18` for the int64 overload) never fires for `precision == INT32_MIN`, where the negation leaves the value negative. That value reaches `get_power_of_10`, which indexes a 19-element static table behind `DCHECK_GE`/`DCHECK_LE` only. The DCHECKs compile out in release builds, so `round(int_col, -2147483648)` reads far outside the table and either faults or returns arbitrary memory as the rounding multiplier. Both overloads are registered in `function_registry_arithmetic.cc`, so the precision comes straight from user SQL.
   
   `truncate_int64_int32` in the same file already compares the signed scale directly (`out_scale < -38`) and is unaffected; the two `round` overloads are the only sites that negate first.
   
   ### What changes are included in this PR?
   
   Check the bound against the signed `precision` before 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.TestRound` covering `std::numeric_limits<int32_t>::min()` for both overloads, matching the existing `truncate_int64_int32` case in the same file. On the unpatched tree the debug build aborts with `extended_math_ops.cc:372: Check failed: (exp) >= (0)`; with the fix the full `gandiva-precompiled-test` suite 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 `round` precision argument.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50545:
URL: https://github.com/apache/arrow/pull/50545#issuecomment-5014955318

   :warning: GitHub issue #50544 **has no components**, please add labels for components.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50545:
URL: https://github.com/apache/arrow/pull/50545#discussion_r3645746895


##########
cpp/src/gandiva/precompiled/extended_math_ops_test.cc:
##########
@@ -203,6 +203,11 @@ TEST(TestExtendedMathOps, TestRound) {
   EXPECT_EQ(round_int64_int32(-23453462343, -4), -23453460000);
   EXPECT_EQ(round_int64_int32(-23453462343, -5), -23453500000);
   EXPECT_EQ(round_int64_int32(345353425343, -12), 0);
+
+  // The most negative precision must be rejected by the range check rather than
+  // negated into an out-of-range table index.
+  EXPECT_EQ(round_int32_int32(1234, std::numeric_limits<int32_t>::min()), 0);
+  EXPECT_EQ(round_int64_int32(345353425343, std::numeric_limits<int32_t>::min()), 0);

Review Comment:
   Would it make sense to also add tests for the `-9`/`-10` boundary (and `-18`/`-19` for the int64 overload)? They could help catch any future off-by-one regressions around the new range check.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision [arrow]

Posted by "Arawoof06 (via GitHub)" <gi...@apache.org>.
Arawoof06 commented on PR #50545:
URL: https://github.com/apache/arrow/pull/50545#issuecomment-6004248975

   Rebased onto current main. The red macOS jobs were the aws-sdk s3fs crash on the old base, unrelated to this change, so CI should settle now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50544: [C++][Gandiva] Fix out-of-bounds read in round with most negative precision [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #50545:
URL: https://github.com/apache/arrow/pull/50545


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50545:
URL: https://github.com/apache/arrow/pull/50545#issuecomment-5014955298

   :warning: GitHub issue #50544 **has been automatically assigned in GitHub** to PR creator.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50544: [C++][Gandiva] fix out-of-bounds read in round with most negative precision [arrow]

Posted by "Arawoof06 (via GitHub)" <gi...@apache.org>.
Arawoof06 commented on code in PR #50545:
URL: https://github.com/apache/arrow/pull/50545#discussion_r3671435742


##########
cpp/src/gandiva/precompiled/extended_math_ops_test.cc:
##########
@@ -203,6 +203,11 @@ TEST(TestExtendedMathOps, TestRound) {
   EXPECT_EQ(round_int64_int32(-23453462343, -4), -23453460000);
   EXPECT_EQ(round_int64_int32(-23453462343, -5), -23453500000);
   EXPECT_EQ(round_int64_int32(345353425343, -12), 0);
+
+  // The most negative precision must be rejected by the range check rather than
+  // negated into an out-of-range table index.
+  EXPECT_EQ(round_int32_int32(1234, std::numeric_limits<int32_t>::min()), 0);
+  EXPECT_EQ(round_int64_int32(345353425343, std::numeric_limits<int32_t>::min()), 0);

Review Comment:
   Good idea, added them. There's now a -9/-10 pair for the int32 overload and -18/-19 for the int64 one, so the last in-range precision still rounds and one past it returns 0. That pins the boundary against any future off-by-one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-50544: [C++][Gandiva] Fix out-of-bounds read in round with most negative precision [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50545:
URL: https://github.com/apache/arrow/pull/50545#issuecomment-6205732827

   :warning: GitHub issue #50544 **has no components**, please add labels for components.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org