fix(high_level): Enhance the reliability of temporary file cleanup#721
fix(high_level): Enhance the reliability of temporary file cleanup#721awwaawwa merged 2 commits intoPDFMathTranslate:mainfrom
Conversation
There was a problem hiding this comment.
PR Overview
This PR enhances the reliability of temporary file cleanup by eliminating unsafe string matching and adding robust error handling.
- Replaces the vulnerable startswith check with pathlib.Path.samefile for file path verification.
- Adds exception handling to log a message and prompt manual deletion when cleanup fails.
Reviewed Changes
| File | Description |
|---|---|
| pdf2zh/high_level.py | Improves temporary file cleanup reliability |
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
pdf2zh/high_level.py:371
- Consider handling cases where a temporary file might reside in a subdirectory of the system temp directory. If such cases are expected, comparing file_path.parent with temp_dir may be insufficient; instead, verify that the resolved file path is within the temp directory's hierarchy.
if file_path.exists() and file_path.parent.samefile(temp_dir):
There was a problem hiding this comment.
PR Overview
This PR enhances the reliability of temporary file cleanup by replacing string-based path matching with pathlib's functionality and adding error handling.
- Replace string matching with Path methods (including is_relative_to)
- Add try/except for file deletion failures and log errors appropriately
Reviewed Changes
| File | Description |
|---|---|
| pdf2zh/high_level.py | Update temporary file removal to use pathlib and add logging for errors |
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
pdf2zh/high_level.py:369
- [nitpick] Consider renaming the variable 'file' to a more descriptive name (e.g., 'temp_file_path_str') to avoid shadowing the built-in and improve clarity.
file_path = Path(file)
|
Thank you for your contribution. According to https://funstory-ai.github.io/BabelDOC/CONTRIBUTOR_REWARD/ , you can apply for a monthly membership redemption code for Immersive Translate. |
原代码问题
startswith可能匹配到/tmp/../etc/passwd类路径C:\Users\~1\...)修改