Validation & limits

Every document is checked before pandoc sees it, so bad files fail in milliseconds with a clear error.

What gets rejected

All of these exit with code 1 and leave any existing output untouched:

ProblemWhy it's rejected
Missing file, a directory, or the wrong extensionThere's nothing to convert
Empty, truncated, or non-zip filesA .docx is a zip archive
Password-protected and legacy .doc filesThese aren't .docx files, even if they're named that way
Encrypted archive membersThey can't be checked
Member paths that are absolute or contain ..A path traversal attempt
Duplicate member namesThe checks and pandoc could read different copies
Missing required partsIt isn't a Word document
XML that isn't well-formed, in any partpandoc can silently lose content from these. A bad relationships file makes it drop every link and still report success
Any XML with a DOCTYPEWord never writes one, and it enables entity attacks
A failed integrity check, or a size in the zip headers that's wrongThe file is corrupt or has been tampered with

Limits

A very small .docx can expand enormously. In testing, a 3 KB document of nested tables exhausted a 4 GB memory limit in pandoc in 15 seconds. Now it's rejected almost instantly, before pandoc runs.

LimitDefaultChange withApplies
Input file size200 MiB--max-file-sizeBefore pandoc
Total uncompressed size1 GiBPython APIBefore pandoc
Size of one XML part64 MiBPython APIBefore pandoc
Files in the archive10,000Python APIBefore pandoc
XML nesting depth256 levelsPython APIBefore pandoc
pandoc memory2 GiB--max-memoryDuring conversion
pandoc run time120 seconds--timeoutDuring conversion

See the Limits class to change the ones without a command-line option.

How much memory you need

Memory depends mostly on how much text the document has, and whether it contains any media. These figures are peak memory measured with pandoc 3.13 on macOS, so treat them as a guide:

DocumentPeak memory
10 MB of document XML, no mediaAbout 320 MB
1 MB of document XML, with an imageAbout 240 MB
5 MB of document XML, with an imageAbout 1.1 GB
10 MB of document XML, with an imageAbout 2.1 GB
A 50 MB image and little textAbout 600 MB

So a document with media takes about 200 MB of memory per MB of XML, because pandoc re-reads the whole page to embed the media. Large images themselves cost little. With the default 2 GiB limit, a document with media can have just under 10 MB of XML. Without media, the 64 MiB part limit normally applies first.

To see how much XML a document has, list its contents and look for word/document.xml:

unzip -l report.docx

Choosing limits

Your own documents, and a long one fails
Raise the limit that the error names: --max-memory 8G or --timeout 600.
Other people's documents
Lower them to what your real documents need, such as --max-memory 512M --timeout 30 --max-file-size 25M. The memory limit is a cap, not a target: a hostile file can use all of it before being stopped.

word2html reads the whole HTML into memory to check it, in addition to pandoc's use. --max-memory only limits pandoc, so allow some headroom on small machines.