Commit d6ce56e
authored
### Rationale for this change
Two Gandiva functions crash when called with extreme integer parameter values:
1. `substring_index(VARCHAR, VARCHAR, INT)` crashes with SIGBUS when count is `INT_MIN`
2. `truncate(BIGINT, INT)` crashes with SIGSEGV when scale is `INT_MAX` or `INT_MIN`
### What changes are included in this PR?
**substring_index fix** (`gdv_string_function_stubs.cc`):
- Replace `abs(cnt)` with safe `int64_t` computation to avoid undefined behavior when `cnt == INT_MIN`
**truncate fix** (`precompiled/extended_math_ops.cc`):
- Return input unchanged for positive scales (no-op for integers)
- Return 0 for scales < -38 to prevent out-of-bounds access in `GetScaleMultiplier`
### Are these changes tested?
Yes. Added coverage for `INT_MAX`/`INT_MIN` values in `gdv_function_stubs_test.cc` and `extended_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) in `substring_index`
- Out-of-bounds array access in `GetScaleMultiplier` when `truncate` receives extreme scale values
* GitHub Issue: #49470
Authored-by: Dmitry Chirkov <dmitry.chirkov@dremio.com>
Signed-off-by: Rossi Sun <zanmato1984@gmail.com>
1 parent a315b96 commit d6ce56e
File tree
4 files changed
+48
-9
lines changed- cpp/src/gandiva
- precompiled
4 files changed
+48
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
570 | 572 | | |
571 | 573 | | |
572 | 574 | | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
573 | 590 | | |
574 | 591 | | |
575 | 592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
432 | 436 | | |
433 | 437 | | |
434 | 438 | | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
439 | 442 | | |
440 | 443 | | |
441 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
389 | 398 | | |
390 | 399 | | |
391 | 400 | | |
392 | 401 | | |
393 | 402 | | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | 403 | | |
398 | | - | |
| 404 | + | |
399 | 405 | | |
400 | 406 | | |
401 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
208 | 209 | | |
209 | 210 | | |
210 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
211 | 224 | | |
212 | 225 | | |
213 | 226 | | |
| |||
0 commit comments