Repository navigation
fix: reject PDF template uploads larger than 10MB (#460) - #722
marcvergees merged 3 commits into
Conversation
POST /templates/upload read the whole file into memory with no size check. Reuse the 413 FILE_TOO_LARGE pattern from the voice input route: check the declared size before reading, then the actual length after.
|
Hi @1sakshm, sorry for the delay responding. Your PR looks good, but we cannot merge it unless it has a frontend implementation too. We should have a message error in the frontend that says so. You can create an issue in the frontend for that and submit your PR. We'll. be able to merge it when we have both things. Lmk if you have problems with anything. You can tag other maintainers too. Marc |
|
Thanks @marcvergees! I'll do that right away: I'll open an issue in fireform-frontend for showing the file-too-large error and send a PR for it, then link both here. |
|
@marcvergees the frontend part is up:
Studio now checks the file size when a PDF is selected and shows the size and the 10 MB limit instead of uploading it. If the backend still returns 413, its message is shown as well. |
Description
POST /templates/uploadread the entire uploaded file into memory without checking its size, so a very large upload could exhaust server memory.This adds a 10 MB limit (
_MAX_TEMPLATE_BYTES) and reuses the same 413 pattern the voice input route already uses (app/api/routes/input.py):file.sizebefore readinglen(content)after readingAppErrorwithstatus_code=413,error_code="FILE_TOO_LARGE"anddetail={"max_size_bytes", "received_size_bytes"}Fixes #460
Note:
POST /forms/transcribe(app/api/routes/forms.py) also callsaudio.file.read()with no limit. I left it out to keep this PR scoped, but I'm happy to add it here or in a follow-up.Type of change
How Has This Been Tested?
test_upload_oversize_pdf_rejectedintests/test_api.py(monkeypatches the limit to 5 bytes and checks for 413 /FILE_TOO_LARGE/ detail values)PYTHONPATH=. python -m pytest tests/→ 174 passedruff check app/→ all checks passedTest Configuration:
Checklist: