Commit 0401a47
authored
fix: Avoid integer overflow in substr() (#20199)
## Rationale for this change
Evaluating `SELECT SUBSTR('', 2, 9223372036854775807);` yields (in a
debug build):
```
thread 'main' (41414592) panicked at datafusion/functions/src/string/split_part.rs:236:47:
attempt to negate with overflow
stack backtrace:
0: __rustc::rust_begin_unwind
at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:698:5
1: core::panicking::panic_fmt
at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:80:14
2: core::panicking::panic_const::panic_const_neg_overflow
at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:180:17
3: datafusion_functions::string::split_part::split_part_impl::{{closure}}
at ./datafusion/functions/src/string/split_part.rs:236:47
4: core::iter::traits::iterator::Iterator::try_for_each::call::{{closure}}
at /Users/neilconway/.rustup/toolchains/1.92.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2485:26
[...]
```
Found via fuzzing.
## Are these changes tested?
Yes, added a unit test.1 parent 85cdf53 commit 0401a47
1 file changed
Lines changed: 22 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
| |||
247 | 250 | | |
248 | 251 | | |
249 | 252 | | |
250 | | - | |
| 253 | + | |
251 | 254 | | |
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
256 | 259 | | |
257 | 260 | | |
258 | | - | |
| 261 | + | |
259 | 262 | | |
260 | | - | |
| 263 | + | |
261 | 264 | | |
262 | | - | |
| 265 | + | |
263 | 266 | | |
264 | 267 | | |
265 | 268 | | |
| |||
810 | 813 | | |
811 | 814 | | |
812 | 815 | | |
813 | | - | |
| 816 | + | |
814 | 817 | | |
815 | 818 | | |
816 | 819 | | |
| |||
821 | 824 | | |
822 | 825 | | |
823 | 826 | | |
824 | | - | |
| 827 | + | |
825 | 828 | | |
826 | 829 | | |
827 | 830 | | |
828 | 831 | | |
829 | 832 | | |
830 | 833 | | |
831 | 834 | | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
832 | 847 | | |
833 | 848 | | |
834 | 849 | | |
| |||
0 commit comments