-
Notifications
You must be signed in to change notification settings - Fork 0
Bound browser-upload chunk reads before allocation #585
Copy link
Copy link
Closed
Labels
backendFastAPI/backend service workFastAPI/backend service workbugSomething isn't workingSomething isn't workingperformancePerformance, bundle size, scalabilityPerformance, bundle size, scalabilitypriority: highHigh-priority correctness or safety issueHigh-priority correctness or safety issuepythonPull requests that update python codePull requests that update python codesecurity
Milestone
Description
Metadata
Metadata
Assignees
Labels
backendFastAPI/backend service workFastAPI/backend service workbugSomething isn't workingSomething isn't workingperformancePerformance, bundle size, scalabilityPerformance, bundle size, scalabilitypriority: highHigh-priority correctness or safety issueHigh-priority correctness or safety issuepythonPull requests that update python codePull requests that update python codesecurity
Parent: #582
backend/routers/uploads.py:289-302reads the whole chunk into memory, then checks whether it was too big:An oversized part is fully allocated before the 413.
Memory and disk are different problems here
The memory bound is easy:
await chunk.read(limit + 1)and reject on overflow.The disk bound cannot be fixed in this handler. Starlette exempts file parts from
max_part_size, so by the time the handler body runs the part has already been spooled to aSpooledTemporaryFile. Bounding that needs aContent-Lengthpre-check or a custom parser.An earlier draft asked to "reject excess before any file write", which is not achievable at this layer. Either descope it or accept a
Content-Lengthguard.The Starlette spool behaviour was confirmed against 1.0.1; this project locks 1.3.1 (
uv.lock:2337-2346). It is long-standing, but worth re-confirming against the pinned version before relying on it.Reuse the helper that already exists
backend/routers/flight_log.py:29andbackend/routers/srt.py:18both define:Consolidate onto one instead of adding a third copy.
Acceptance criteria
Checks