[Bug] xlsx stream write leaves temp file
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
バグは WriteContextImpl.java の 663-694 行目にあります。まず doOutputStreamEncrypt07 メソッドを読んで、一時ファイルのフローを理解してください。修正には、すべての終了パスで tempXlsx.delete() が実行されるように try-finally ブロックを再構築することが含まれます。暗号化を使用した XLSX 書き込みの既存のテストを実行し、修正が既存の機能を損なわないことを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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!
- 主要言語
- Java
- スター
- 6.2k
- フォーク
- 532
- 平均マージ
- 11時間 55分
- マージ済み PR(30日)
- 22
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/fesod のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
apache/fesod#1131 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
beehive-lab/TornadoVM#1151 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
FasterXML/jackson-dataformats-binary#823 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信