Guard hi-res PDF rendering against oversized pages#4344
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 37f65d2. Configure here.
| @property | ||
| def PDF_RENDER_MAX_PIXELS_PER_PAGE(self) -> int: | ||
| """Maximum rendered pixels allowed for a single PDF page.""" | ||
| return self._get_int("PDF_RENDER_MAX_PIXELS_PER_PAGE", 1_000_000_000) |
There was a problem hiding this comment.
Default pixel limit exceeds PIL safety limit
Medium Severity
The default PDF_RENDER_MAX_PIXELS_PER_PAGE of 1,000,000,000 (1 billion) is twice as high as PILImage.MAX_IMAGE_PIXELS which is set to 5e8 (500 million) at module level. This means with default settings, any page rendering between 500M and 1B pixels passes the preflight check but still triggers a PIL DecompressionBombError during rasterization — after the resource-intensive poppler rendering step has already allocated memory. The preflight check's purpose is to reject oversized pages before rasterization, but the default value makes it ineffective for the exact range PIL would catch.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 37f65d2. Configure here.


Adds a preflight check for hi-res PDF rendering that estimates per-page rendered pixels before rasterization and rejects pages that exceed the configured safe limit.
Note
Medium Risk
Changes hi-res PDF partitioning to fail early with
UnprocessableEntityErrorwhen a page would render beyond a new per-page pixel cap, which may reject documents that previously processed (or OOMed) depending on DPI/page size and env configuration.Overview
Adds a hi-res PDF render preflight guard that estimates per-page rasterized pixel counts (from
cropbox/mediaboxat the configured DPI) and raisesUnprocessableEntityErrorbefore any rendering when a page exceeds a configurable maximum.Introduces new env config
PDF_RENDER_MAX_PIXELS_PER_PAGE(default1_000_000_000,0disables), wires the check intopartition_pdf_or_imagefor non-image hi-res PDFs, and adds unit tests covering limit exceeded/allowed, disablement, and file-cursor restoration. Also bumps version to0.22.24and documents the fix in the changelog.Reviewed by Cursor Bugbot for commit 37f65d2. Bugbot is set up for automated code reviews on this repo. Configure here.