[Bug] xlsx stream write leaves temp file
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 75/100
Línea de trabajo
El error está en WriteContextImpl.java en las líneas 663-694. Comience leyendo el método doOutputStreamEncrypt07 para comprender el flujo del archivo temporal. La solución implica reestructurar los bloques try-finally para garantizar que tempXlsx.delete() se ejecute en todas las rutas de salida. Ejecute las pruebas existentes para la escritura de XLSX con cifrado para verificar que la solución no rompa la funcionalidad existente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Search before asking
- I searched in the issues and found nothing similar.
Fesod version
main
JDK version
any
Operating system
Linux
Steps To Reproduce
When an xlsx is written to an OutputStream with .password(...), WriteContextImpl#doOutputStreamEncrypt07() first writes the workbook unencrypted to a temp file, then encrypts that file into the caller's stream (code). The temp file is deleted on every path except one:
FileOutputStream tempFileOutputStream = new FileOutputStream(tempXlsx);
try {
writeWorkbookHolder.getWorkbook().write(tempFileOutputStream); // 1. fails, e.g. disk full
} finally {
try {
writeWorkbookHolder.getWorkbook().close();
tempFileOutputStream.close(); // 2. succeeds
} catch (Exception e) {
if (!tempXlsx.delete()) { ... } // only runs if 2. fails
throw e;
}
}
try (POIFSFileSystem fileSystem = openFileSystemAndEncrypt(tempXlsx)) {
fileSystem.writeFilesystem(writeWorkbookHolder.getOutputStream());
} finally {
if (!tempXlsx.delete()) { ... } // never reached after 1.
}
If writing the temp file fails but closing succeeds, the exception from step 1 leaves the method without ever reaching a delete.
Current Behavior
The partly or fully written, unencrypted xlsx stays in Fesod's temp directory.
Expected Behavior
The temp file is deleted however doOutputStreamEncrypt07() exits, including when writing it fails.
Anything else?
Proposed fix. Move the delete into one outer finally that covers both the temp-file write and the encryption step:
FileOutputStream tempFileOutputStream = new FileOutputStream(tempXlsx);
try {
try {
writeWorkbookHolder.getWorkbook().write(tempFileOutputStream);
} finally {
writeWorkbookHolder.getWorkbook().close();
tempFileOutputStream.close();
}
try (POIFSFileSystem fileSystem = openFileSystemAndEncrypt(tempXlsx)) {
fileSystem.writeFilesystem(writeWorkbookHolder.getOutputStream());
}
} finally {
if (!tempXlsx.delete()) {
throw new ExcelGenerateException("Can not delete temp File!");
}
}
- A successful write, a failed close and a failed encryption behave as before: the temp file is deleted in each case.
- A failed write now deletes the temp file too.
Are you willing to submit a PR?
- I'm willing to submit a PR!
- Lenguaje dominante
- Java
- Estrellas
- 6.2k
- Forks
- 532
- Merge medio
- 11 h 55 min
- PR fusionados (30 d)
- 22
Preparar el entorno
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 apache/fesod
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/fesod
Issues similares
-
area/frontend good first issue kind/cooldown
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
beehive-lab/TornadoVM#1151 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
(cbor) `maxStringLength` not consistently checked for chunked (indefinite-length) text valuesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
FasterXML/jackson-dataformats-binary#823 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día