Skip to content

fix: return execution error instead of capacity overflow panic in array_resize#23306

Open
buraksenn wants to merge 1 commit into
apache:mainfrom
buraksenn:fix-array-resize-overflow-panic
Open

fix: return execution error instead of capacity overflow panic in array_resize#23306
buraksenn wants to merge 1 commit into
apache:mainfrom
buraksenn:fix-array-resize-overflow-panic

Conversation

@buraksenn

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Please check #22227

What changes are included in this PR?

Instead of panicking we return execution error buy checking sizes in array_resize.

Outcome is:

➜  datafusion git:(fix-array-resize-overflow-panic)  cargo run -p datafusion-cli -- -c "SELECT array_resize(make_array(1), 9223372036854775807, 0)"
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s
     Running `target/debug/datafusion-cli -c 'SELECT array_resize(make_array(1), 9223372036854775807, 0)'`
DataFusion CLI v54.0.0
Error: Execution error: array_resize: resulting array of 9223372036854775807 elements exceeds the maximum array size

in issue it was:
image

Are these changes tested?

yes. added new unit and slt tests

Are there any user-facing changes?

instead of panic users will see execution error

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Jul 3, 2026
/// Largest element count whose eager value buffer stays within `isize::MAX`
/// bytes, so `array_resize` rejects oversized results instead of panicking.
/// Only primitive and `FixedSizeBinary` leaves are byte-exact.
fn max_resize_values(value_type: &DataType) -> usize {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the compiler prob materialize it, but would it be better to prematerialize it manually through

static LazyLock<HashMap<DataType, usize>> ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are parameterized types I would need to keep match right? I'm not sure it would be better but can't say I've a strong opinion. If you say go for it I can change it that way

@comphead

comphead commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

benchmark run array_resize

@comphead

comphead commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

run benchmark array_resize

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4883194475-844-nh2r2 6.12.85+ #1 SMP Mon May 11 08:17:35 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing fix-array-resize-overflow-panic (26928b9) to e4aa41d (merge-base) diff using: array_resize
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                HEAD                                    fix-array-resize-overflow-panic
-----                                                ----                                    -------------------------------
array_resize_i64/grow_default_null_fill_10_to_500    1.00    138.5±2.89µs        ? ?/sec     1.01    140.5±4.44µs        ? ?/sec
array_resize_i64/grow_uniform_fill_10_to_500         1.08   344.3±88.73µs        ? ?/sec     1.00   320.0±12.30µs        ? ?/sec
array_resize_i64/grow_variable_fill_10_to_500        1.00  1975.0±149.60µs        ? ?/sec    1.00  1974.0±149.10µs        ? ?/sec
array_resize_i64/mixed_grow_shrink_1000x_100         1.05     80.5±0.23µs        ? ?/sec     1.00     76.5±0.34µs        ? ?/sec
array_resize_i64/shrink_uniform_fill_500_to_10       1.00     10.6±0.07µs        ? ?/sec     1.02     10.8±0.03µs        ? ?/sec

Resource Usage

array_resize — base (merge-base)

Metric Value
Wall time 355.1s
Peak memory 46.2 MiB
Avg memory 6.3 MiB
CPU user 66.3s
CPU sys 0.1s
Peak spill 0 B

array_resize — branch

Metric Value
Wall time 310.1s
Peak memory 73.8 MiB
Avg memory 8.7 MiB
CPU user 66.9s
CPU sys 0.1s
Peak spill 0 B

File an issue against this benchmark runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: array_resize capacity overflow with large target size

3 participants