Commit 7ad8e2c
authored
fix array_repeat capacity overflow on constant scalar with large count (#22305)
## Which issue does this PR close?
- Closes #22228 .
## Rationale for this change
`array_repeat` still panics for oversized repeat counts in the
constant-scalar path. The simplest reproducer is:
```sql
SELECT array_repeat(1, 9223372036854775807)
```
Unlike the previously reported `array_repeat` overflow cases, this path
does not sum counts across rows and does not multiply nested list
lengths, but it still reaches an unchecked `Vec` preallocation and
panics with `capacity overflow`.
This change makes `array_repeat` reject oversized output lengths up
front and return a normal execution error instead of panicking.
## What changes are included in this PR?
This PR adds explicit bounds checks in repeat.rs so `array_repeat`
validates requested output sizes before allocating buffers.
The main changes are:
- Move repeat-length accumulation into shared checked helpers.
- Reject oversized output lengths with:
`array_repeat: requested length exceeds maximum array size`
- Guard both scalar and list repeat paths so they fail consistently
before hitting unchecked allocation or arithmetic overflow.
- Reuse precomputed outer offsets for the list path instead of
rebuilding them from unchecked lengths.
## Are these changes tested?
Yes.
This PR adds a regression test in repeat.rs covering the constant-scalar
reproducer with `i64::MAX` as the repeat count and verifies that
`array_repeat` returns an execution error rather than panicking.
Validated with:
```bash
cargo test -p datafusion-functions-nested scalar_count_exceeding_max_array_size_returns_error --lib
```
## Are there any user-facing changes?
Yes.
Previously, oversized `array_repeat` calls could panic the process.
After this change, they return a regular execution error:
```text
array_repeat: requested length exceeds maximum array size
```1 parent 94c58d0 commit 7ad8e2c
2 files changed
Lines changed: 111 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| |||
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
178 | | - | |
179 | | - | |
180 | | - | |
| 182 | + | |
181 | 183 | | |
182 | 184 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | 185 | | |
187 | 186 | | |
188 | 187 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | 188 | | |
201 | 189 | | |
202 | 190 | | |
| |||
231 | 219 | | |
232 | 220 | | |
233 | 221 | | |
| 222 | + | |
234 | 223 | | |
235 | 224 | | |
236 | | - | |
237 | 225 | | |
238 | 226 | | |
239 | 227 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
247 | 234 | | |
248 | 235 | | |
249 | 236 | | |
250 | 237 | | |
| 238 | + | |
251 | 239 | | |
252 | 240 | | |
253 | 241 | | |
| |||
262 | 250 | | |
263 | 251 | | |
264 | 252 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 253 | + | |
| 254 | + | |
270 | 255 | | |
271 | 256 | | |
272 | 257 | | |
| |||
299 | 284 | | |
300 | 285 | | |
301 | 286 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
| 287 | + | |
307 | 288 | | |
308 | 289 | | |
309 | 290 | | |
310 | 291 | | |
311 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
312 | 366 | | |
313 | 367 | | |
314 | 368 | | |
| |||
320 | 374 | | |
321 | 375 | | |
322 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
0 commit comments