docling icon indicating copy to clipboard operation
docling copied to clipboard

.doc/.rtf/.ppt: a failed LibreOffice conversion raises out of convert_all(raises_on_error=False) and stops the batch

Open dlaszlo opened this issue 3 weeks ago • 1 comments

Bug

When LibreOffice exits with a non-zero status, or does not finish within its 120 s timeout, on a .doc, .rtf or .ppt input, subprocess.CalledProcessError / subprocess.TimeoutExpired escapes convert() and convert_all() even with raises_on_error=False. In convert_all() the remaining inputs are not converted.

convert_to_modern_format calls _run_hardened_soffice without catching its errors (utils.py L308-L318); its docstring says it raises RuntimeError when the subprocess fails (L288-L290). It runs in the backend constructors, and InputDocument records only a DocumentLoadError, OSError or RuntimeError from there (document.py L321-L327, L231, L241). Anything else leaves the input generator (L890) and ends the batch.

Impact

  • The CLI (default --no-abort-on-error) stops at the first file: docling broken.doc second.html --output out does not convert second.html and writes nothing; it ends with an uncaught CalledProcessError traceback and exit status 1.
  • A real .doc, .rtf or .ppt cut to half its length triggers it as well.
  • The timeout: with a stand-in soffice that outlives its 120 s timeout, TimeoutExpired escapes and the next input is not converted.
  • .xls goes through the same call, but a malformed or truncated .xls did not trigger it here: LibreOffice converted both with exit status 0.

Steps to reproduce

Needs LibreOffice on PATH. The input is a malformed .doc.

from io import BytesIO

from docling.datamodel.base_models import DocumentStream
from docling.document_converter import DocumentConverter

# A malformed .doc: an OLE2 signature followed by junk. LibreOffice exits with status 1.
junk = b"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1" + b"\x00" * 600 + b"junk" * 200
html = b"<html><body><p>Second document.</p></body></html>"

results = DocumentConverter().convert_all(
    [
        DocumentStream(name="broken.doc", stream=BytesIO(junk)),
        DocumentStream(name="second.html", stream=BytesIO(html)),
    ],
    raises_on_error=False,
)
try:
    for result in results:
        print(result.input.file.name, result.status.value, [e.error_message for e in result.errors])
except Exception as exc:
    print("raised:", type(exc).__module__ + "." + type(exc).__qualname__)

Output:

raised: subprocess.CalledProcessError

Expected: broken.doc FAILURE with an error, then second.html SUCCESS.

Possible fix

In convert_to_modern_format, catch both exceptions around the _run_hardened_soffice call (utils.py L308-L318) and raise RuntimeError, as its docstring promises; InputDocument then records a FAILURE and the batch continues.

Related: #770 (the same contract for HTTP errors, handled since #3609).

Docling version

$ docling --version
Docling version: 2.150.0
Docling Core version: 2.106.0
Docling IBM Models version: 4.0.4
Docling Parse version: 7.25.0
Python: cpython-314 (3.14.4)
Platform: Linux-7.0.0-43-generic-x86_64-with-glibc2.43

LibreOffice 26.2.6.3. The permalinks are to the docling v2.150.0 tag.

Python version

3.14.4

dlaszlo avatar Nov 11 '26 20:11 dlaszlo

Classification labels added: bug, priority:medium, docx, pptx.

These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.

github-actions[bot] avatar Nov 16 '26 15:11 github-actions[bot]