docling icon indicating copy to clipboard operation
docling copied to clipboard

libpdfium crash with "could not find the page-dimensions" error on complex PDFs

Open riccardo-rav opened this issue 1 year ago • 2 comments

Bug

Docling fails to process certain complex PDFs with a "could not find the page-dimensions" error, followed by libpdfium crashes during object destruction. This affects large, complex PDF documents and causes ConversionStatus.FAILURE.

Error Details: ConversionError: Conversion failed for: CUDA_C_Programming_Guide.pdf with status: ConversionStatus.FAILURE RuntimeError: could not find the page-dimensions of page idx=0 for model PdfMode.AUTO using ImageFormat.AUTO

Crash Report (libpdfium): Thread 7 Crashed:: FX_IMAGE_THREAD 0 libpdfium.dylib 0x00000001254c0c6f CPDF_Color::CPDF_Color() + 15 1 libpdfium.dylib 0x00000001254c0a4f CPDF_ColorSpace::CPDF_ColorSpace() + 63 2 libpdfium.dylib 0x00000001254c4c9f std::__1::default_delete::operator()(CPDF_ColorSpace*) const + 15 3 libpdfium.dylib 0x00000001254c4c6f std::__1::unique_ptr<CPDF_ColorSpace, std::__1::default_delete >::reset(CPDF_ColorSpace*) + 47 4 libpdfium.dylib 0x00000001254c4c27 std::__1::unique_ptr<CPDF_ColorSpace, std::__1::default_delete >::unique_ptr() + 23 5 libpdfium.dylib 0x00000001254c0b23 CPDF_ColorSpace::CPDF_ColorSpace() + 275

Steps to reproduce

  1. Download a large, complex PDF (e.g., CUDA C Programming Guide - ~50MB, 590 pages with technical diagrams)
  2. Create DocumentConverter with standard configuration:
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions

pipeline_options = PdfPipelineOptions()
pdf_format_option = PdfFormatOption(pipeline_options=pipeline_options)

converter = DocumentConverter(
    format_options={
        InputFormat.PDF: pdf_format_option,
    }
)

# This fails with page-dimensions error
result = converter.convert("CUDA_C_Programming_Guide.pdf")

3. Observe "page-dimensions" error followed by potential libpdfium crash

Note: PDF structure is valid according to PyPDF2 and other parsers. All pages have proper MediaBox definitions when analyzed with standard PDF tools. Issue
appears specific to libpdfium's page dimension detection algorithm.

Docling version

Unable to determine version programmatically, using latest available version with DocumentConverter

Python version

Python 3.13.4

**Additional Context:**
- **Platform**: macOS (Darwin 23.5.0)
- **Impact**: High severity - causes complete conversion failure for certain complex PDF types
- **Workaround**: We've implemented a PyPDF2 fallback mechanism that successfully processes the same PDFs that crash libpdfium
- **Tested Conservative Settings**: Disabled OCR, table analysis, image processing - all still fail with same error

This bug significantly impacts production PDF processing workflows. The crash occurs during object destruction suggesting memory corruption in the libpdfium
layer.

riccardo-rav avatar Nov 07 '25 08:11 riccardo-rav

Hi @riccardo-ravaro! I'm Dosu and I’m helping the docling team.

This is a known issue with Docling's libpdfium backend, especially when processing large or complex PDFs. The "could not find the page-dimensions" error is typically triggered when libpdfium fails to extract standard page dimension metadata, even if other parsers like PyPDF2 can read the file correctly. The subsequent crash during object destruction points to memory corruption, often caused by thread safety issues in native libraries like pypdfium2/libpdfium, particularly in multi-threaded environments or with newer Python/glibc versions example.

Recent updates have improved thread safety in Docling's PDF pipeline—make sure you're using the latest Docling and pypdfium2 versions example. For safer concurrent processing, use ProcessPoolExecutor instead of ThreadPoolExecutor, and always create a new DocumentConverter instance per thread or process example.

Workarounds include: splitting large PDFs into smaller parts, using the page_range parameter, and processing documents in smaller batches to avoid memory exhaustion and crashes example. You can also manually call unload() on the backend and page backends after each conversion, or recreate the DocumentConverter instance to minimize memory leaks example.

If you need to process PDFs that consistently fail with libpdfium, using PyPDF2 or PyMuPDF to set valid mediabox and cropbox metadata on all pages before conversion can help example. Switching the PDF backend to 'pypdfium2' may avoid the page-dimensions error, but be aware that this can result in output where text is converted to embedded images, requiring OCR for extraction example.

If the underlying native library is not fully compatible or has latent bugs, there may be no complete workaround except updating dependencies or running Docling via docling-serve with multiple workers example.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about docling with Dosu Add Dosu to your team

dosubot[bot] avatar Nov 07 '25 09:11 dosubot[bot]

Fixed v2.74.0

dolfim-ibm avatar Feb 18 '26 07:02 dolfim-ibm