`repeat` on `LargeUtf8` aborts the process on a result size no allocation can satisfy

Abierto Apto para principiantes
#26,948 1 comentario 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@huong8373tt-beep ya está trabajando en esto.

Desde el 2/11/2026.

  • #26957 de @shahwazreza — abierto
  • #27010 de @huong8373tt-beep — cerrado sin fusionar

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
backend

Línea de trabajo

Comienza en datafusion/functions/src/string/repeat.rs, comparando el límite de LargeUtf8 en la ruta escalar cerca de las líneas 127-128 con la ruta de array cerca de las líneas 227-228. Lee test_repeat_string_array_overflow y el fragmento de reproducción, luego elige el enfoque de tope fijo o try_reserve y haz que ambas rutas devuelvan un error para un conteo de 1 << 60. Añade una prueba de regresión que cubra el LargeUtf8 escalar y el constructor de arrays, y ejecuta las pruebas de repeat.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug good first issue

repeat on LargeUtf8 aborts the process on a result size no allocation can satisfy

Describe the bug

repeat caps the result at i32::MAX bytes for Utf8 and Utf8View, and returns an error above that. For LargeUtf8 the cap is i64::MAX, in both the scalar path and the array path. That cap admits sizes no allocation can satisfy. A result of 2^60 bytes (1 EiB) is larger than the virtual address space of x86_64 (48 or 57 bits) and aarch64 (at most 52 bits), so the allocator refuses it at once, whatever memory the machine has:

  • With both arguments scalar, s.repeat(count) cannot fail gracefully, so the refused allocation aborts the process: memory allocation of 1152921504606846976 bytes failed.
  • With an array of strings, the builder panics: failed to allocate memory for layout Layout { size: 1152921504606846976, align: 64 (1 << 6) }.

The existing test_repeat_string_array_overflow uses a count of i64::MAX, which the overflow check catches before any allocation.

To Reproduce

On main at 926901f90:

use std::sync::Arc;

use arrow::datatypes::Field;
use datafusion_common::ScalarValue;
use datafusion_common::config::ConfigOptions;
use datafusion_expr::{ColumnarValue, ReturnFieldArgs, ScalarFunctionArgs};
use datafusion_functions::string::repeat;

let udf = repeat();
let s = ScalarValue::LargeUtf8(Some("a".to_string()));
// With ScalarValue::Utf8: Err(Execution("string size overflow on repeat, max size is 2147483647, but got 1152921504606846976"))
let n = ScalarValue::Int64(Some(1 << 60));
let arg_fields = vec![
    Arc::new(Field::new("s", s.data_type(), true)),
    Arc::new(Field::new("n", n.data_type(), true)),
];
let return_field = udf
    .return_field_from_args(ReturnFieldArgs {
        arg_fields: &arg_fields,
        scalar_arguments: &[Some(&s), Some(&n)],
    })
    .unwrap();
let result = udf.invoke_with_args(ScalarFunctionArgs {
    args: vec![ColumnarValue::Scalar(s), ColumnarValue::Scalar(n)],
    arg_fields,
    number_rows: 1,
    return_field,
    config_options: Arc::new(ConfigOptions::default()),
});
// aborts: memory allocation of 1152921504606846976 bytes failed
Expected behavior

An error, as for Utf8, instead of an abort. Two fixes seem possible:

  • A fixed cap for LargeUtf8. PostgreSQL's repeat returns "requested length too large" above MaxAllocSize, 1 GB minus 1 (oracle_compat.c). DuckDB's strings are limited to u32::MAX bytes (MAX_STRING_SIZE).
  • Fallible allocation, such as try_reserve, so that a refused allocation becomes an error.

Which one should repeat use? Neither guards against an allocation that succeeds under overcommit and fails later when the pages are touched. Both turn this case, where the allocator refuses up front, into an error. #22688 tracks checked size accounting for string builders in general.

Additional context

Found by property-based tests that call each function with generated arguments, including large counts.

Willingness to contribute

I cannot contribute a fix for this bug at this time

Lenguaje dominante
Rust
Estrellas
9.6k
Forks
2.6k
Merge medio
4 d 5 h
PR fusionados (30 d)
319

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/datafusion

Todos los issues de apache/datafusion

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.