Skip to content

#189- remove temporary outfile#190

Open
Cubix33 wants to merge 1 commit intofireform-core:mainfrom
Cubix33:remove-temp-outfile
Open

#189- remove temporary outfile#190
Cubix33 wants to merge 1 commit intofireform-core:mainfrom
Cubix33:remove-temp-outfile

Conversation

@Cubix33
Copy link

@Cubix33 Cubix33 commented Mar 5, 2026

Closes #189

Fix: Implement secure temporary file handling and cleanup in main.py

📝 Description

This PR addresses an issue where main.py leaves a hardcoded intermediate PDF (temp_outfile.pdf) on the disk after execution.

Previously, if multiple requests were processed simultaneously, the hardcoded filename could cause race conditions. Furthermore, if the script crashed during execution, the temporary file was never deleted, leading to directory clutter and potential security risks by leaving template structures on the disk.

🛠️ Changes Made

  • Replaced the hardcoded temp_outfile.pdf string with Python's built-in tempfile.mkstemp() to generate secure, collision-proof temporary file paths dynamically.
  • Wrapped the core PDF extraction and filling logic in a try...finally block.
  • Added os.remove() to the finally block to guarantee the OS purges the temporary file immediately after execution, regardless of whether the script succeeds or throws an exception.

🧪 How to Test

  1. Run python src/main.py (or make exec if using Docker).
  2. Verify the script completes and outputs the final filled PDF successfully.
  3. Check the root directory to confirm temp_outfile.pdf (or any other randomized .pdf temp files) are completely removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CHORE]: Implement Temporary File Garbage Collection in main.py

1 participant