You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(parser): fitz.open(stream=data) loads entire PDF into RAM with no size cap, enabling OOM on large uploads #246
ingestion/parser.py calls fitz.open(stream=data, filetype='pdf') where data is the raw bytes of the uploaded PDF. PyMuPDF copies the entire byte string into an in-memory stream, and IngestInput.data also holds those bytes simultaneously. A single oversized upload can double peak memory and OOM the worker process with no size guard.
Root Cause
ingestion/parser.py around line 133:
defparse(self, data: bytes) ->tuple[ParsedPage, ...]:
doc=fitz.open(stream=data, filetype='pdf') # ← entire bytes loaded into RAM# data is also still held by the caller as IngestInput.data# peak memory ≈ 2 × len(data) + parsed output
There is no file-size check before calling parse(), no streaming mode, and no limit in the pipeline entry point.
Failure Scenario
Tenant uploads a 2 GB PDF via the API.
The API layer reads the full body into memory as bytes.
PipelineIngestor._run_pipeline() passes those bytes to parser.parse().
fitz.open(stream=data) allocates another ~2 GB buffer internally.
Peak RSS ≈ 4+ GB → worker OOM-killed → all in-flight requests on that worker fail simultaneously.
Proposed Fix
Two layers of defense:
1. API-level size limit (in backend/app/api/documents.py):
MAX_UPLOAD_BYTES=100*1024*1024# 100 MBiflen(awaitfile.read(MAX_UPLOAD_BYTES+1)) >MAX_UPLOAD_BYTES:
raiseHTTPException(status_code=413, detail="File too large (max 100 MB)")
Activity
piyushmakhija28 commentedon Jun 21, 2026
Fixed in PR #280 (Sprint R3/R4: fix(sprint-r3): root-cause fixes for all 39 bugs from code review round 3 + Sprint R4 round 4)