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
Add configurable resource limits to PDF conversion - #2951
Dense PDFs could create unbounded character objects during extraction. Add PdfLimits to check budgets before character allocation and bound PDF input and extracted output, including the OCR converter.
Defaults are 128 MiB of input, 100,000 character allocations per page, 2 million allocations across extraction attempts, and 10 million output characters. Limit failures terminate conversion without parser fallback. Streamed input—including CLI stdin, HTTP responses, and data URIs—is processed in chunks and spooled as needed.
Update PDF signature detection logic to check for the presence of '%PDF-' within the first 1024 bytes and adjust prefix length to 1028 bytes.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical PDF guard gaps let unhinted, prefixed PDFs bypass early size checks and block archive fallback for oversized ZIPs with misleading PDF metadata.
Acquisition guards reject oversized PDF input before converter selection, but seekable/local inputs are checked only inside the native PDF converters. With cu_endpoint or docintel_endpoint, the same oversized PDF can therefore be uploaded from a local file or seekable stream while HTTP, data URIs, and stdin fail. Define whether max_input_bytes covers all PDF converters or native extraction only, and enforce that scope consistently across input sources.
Preserve base64 padding behavior across chunk boundaries
Counting ignored = characters toward complete quanta changes the previous permissive base64.b64decode behavior. For example, QUFB= followed by QUFB repeated 17,000 times previously decoded successfully, but now raises Incorrect padding at the first chunk boundary. Preserve the decoder's padding and termination behavior across chunks, and add this boundary regression.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
PDF acquisition can exceed configured byte caps, nested conversions can ignore stricter limits, and chunked Base64 decoding can reject or silently truncate previously accepted inputs.
When a registered converter supplies stricter pdf_limits inside an existing MarkItDown conversion, this branch silently keeps the outer limits. The requested cap is therefore not enforced. Apply nested limits without resetting allocation counters, or reject conflicting explicit overrides while preserving normal nested conversions.
Headers with trailing spaces or tabs, such as %PDF-1.7 \n, never match this check, although pdfminer skips the comment through its line ending (default-branch evidence). Without a PDF extension/MIME hint, recognized stays false, so stdin, HTTP, and data-URI acquisition buffer the entire input regardless of max_input_bytes; read_pdf() rejects it only afterwards. Allow trailing horizontal whitespace before the line ending and add an acquisition-limit regression for this case.
Chunking changes the previous permissive Base64 decoding: "=" + "QUJD" * 20000 now raises Incorrect padding, while "QUJD====" + "REVG" * 20000 silently truncates after the first chunk. Preserve the decoder's treatment of ignored padding across chunk boundaries, and stop only when padding actually terminates decoding. Add regressions for both cases.
Enforce OCR output limit before requesting more images
The per-page OCR counter ignores output already retained in markdown_content. If earlier pages nearly exhaust the limit, this loop can still send every image to the OCR service before a later append rejects the result. Check retained OCR text against the accumulated output as each image returns, before requesting the next image.
Avoid PDF size failures for recognizable non-PDF content
A PDF extension or MIME hint subjects any non-ZIP payload to a terminal PDF input limit, even when content detection identifies text or HTML. Oversized mislabeled input therefore aborts instead of reaching its content-based converter, both during streamed acquisition and in read_pdf() for seekable input. Rule out recognizable non-PDF content before making a PDF size failure terminal in either path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dense PDFs could create unbounded character objects during extraction. Add PdfLimits to check budgets before character allocation and bound PDF input and extracted output, including the OCR converter.
Defaults are 128 MiB of input, 100,000 character allocations per page, 2 million allocations across extraction attempts, and 10 million output characters. Limit failures terminate conversion without parser fallback. Streamed input—including CLI stdin, HTTP responses, and data URIs—is processed in chunks and spooled as needed.