Memory allocation/deallocation mismatch in fuzz_array.c causes immediate crash with AddressSanitizer
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Área
- testing-qa
Línea de trabajo
Lee projects/cups/fuzzer/fuzz_array.c alrededor de la limpieza en las líneas 158-162 y projects/cups/fuzzer/fuzz_helpers.cpp alrededor de generate_fuzz_array_data y free_fuzz_array_data. Compila el fuzzer de CUPS con AddressSanitizer y ejecuta fuzz_array con una entrada; el trabajo está terminado cuando desaparece el bloqueo alloc-dealloc-mismatch y el fuzzing de arrays continúa.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
Summary
The fuzz_array.c fuzzer has a critical memory management bug that causes it to crash immediately when built with AddressSanitizer. The fuzzer uses C's free() function to deallocate memory allocated with C++'s new[] operator,
violating C++ memory management rules.
Impact
- Status: Blocks all fuzzing of CUPS array functionality
- Scope: Affects anyone running
fuzz_arraywith AddressSanitizer (including OSS-Fuzz)
The fuzzer crashes on the very first test case, achieving zero code coverage and preventing discovery of real bugs in CUPS.
Root Cause
Allocation (C++ new[]) in fuzz_helpers.cpp:21,24:
void generate_fuzz_array_data(const uint8_t *data, size_t size, FuzzArray *outData) {
// ...
outData->str1 = new char[fuzz_str1.length() + 1]; // C++ new[]
outData->str2 = new char[fuzz_str2.length() + 1]; // C++ new[]
}
Deallocation (C free()) in fuzz_array.c:161-162:
free(first_string); // ❌ Wrong: should use delete[]
free(second_string); // ❌ Wrong: should use delete[]
AddressSanitizer Error
==1==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs free)
#0 in free
#1 in LLVMFuzzerTestOneInput fuzz_array.c:161:3
0x7be2be1e08d0 is located 0 bytes inside of 2-byte region
allocated by thread T0 here:
#0 in operator new[](unsigned long)
#1 in generate_fuzz_array_data fuzz_helpers.cpp:21:21
#2 in LLVMFuzzerTestOneInput fuzz_array.c:51:3
SUMMARY: AddressSanitizer: alloc-dealloc-mismatch fuzz_array.c:161:3
Reproduction Steps
1. Build fuzzers with AddressSanitizer:
# Using OSS-Fuzz infrastructure
python3 infra/helper.py build_fuzzers --sanitizer address cups
2. Run the fuzzer with any input:
./fuzz_array test_input
3. Expected: Fuzzer crashes immediately with alloc-dealloc-mismatch
Solution
The codebase already provides the correct deallocation function in fuzz_helpers.cpp:29-32:
void free_fuzz_array_data(FuzzArray *data) {
delete[] data->str1; // ✓ Correct
delete[] data->str2; // ✓ Correct
}
Fix: Replace the incorrect free() calls with the proper helper function.
Proposed Patch
--- a/projects/cups/fuzzer/fuzz_array.c
+++ b/projects/cups/fuzzer/fuzz_array.c
@@ -158,8 +158,8 @@
cupsArrayDelete(array);
cupsArrayDelete(dup_array);
- free(first_string);
- free(second_string);
+ // Free fuzz input data using the correct C++ delete[]
+ free_fuzz_array_data(&fuzzInput);
if (status != 0) {
abort();
Testing
After applying the patch:
1. Rebuild the fuzzer with AddressSanitizer
2. Run with test inputs - no crash should occur
3. Fuzzer should successfully test CUPS array operations
Additional Context
- C++ standard requires matching allocation/deallocation pairs:
- new → delete
- new[] → delete[]
- malloc() → free()
- Mixing these causes undefined behavior
- AddressSanitizer correctly detects this violation
The irony is that the correct solution (free_fuzz_array_data()) was already implemented in the codebase, but fuzz_array.c doesn't use it.
Environment
- Compiler: Clang with AddressSanitizer
- Platform: Any (bug is platform-independent C++ standard violation)
- OSS-Fuzz: Affected
- Lenguaje dominante
- C
- Estrellas
- 8
- Forks
- 18
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de OpenPrinting/fuzzing
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
OpenPrinting/fuzzing#45 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
OpenPrinting/fuzzing#47 · 4 comentarios · 1 reacción ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 52/100
OpenPrinting/fuzzing#46 ·
-
Memory leak in cups `fuzz_ppd` harnessPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug good first issue
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
OpenPrinting/fuzzing#7 ·
-
Failed coverage building for cups-filtersPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertogood first issue
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
OpenPrinting/fuzzing#5 · 1 comentario ·
Todos los issues de OpenPrinting/fuzzing
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
DarkFlippers/qUnleashed#240 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
HarbourMasters/Shipwright#7320 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
FujiNetWIFI/fujinet-firmware#1834 ·
Los mantenedores suelen responder en 1 día
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día