How to Diagnose and Repair a Corrupted DOCX File

November 08, 2026 · DOCX.now Editorial · DOCX Essentials

Separate storage failure, structural damage and unsupported DOCX features before attempting repair.

Classify the Failure Before Acting

A corrupted DOCX file is never a single problem. Before any repair attempt, separate three distinct failure modes: storage-layer corruption (damaged bytes on disk), structural damage (broken ZIP container or malformed XML), and unsupported features (valid DOCX content that a specific application cannot parse). Each mode demands different tools and carries different recovery limits.

Open the file in a hex editor or use a command-line tool that reports the first four bytes. A valid DOCX file begins with PK (0x50 0x4B), the ZIP local file header signature.

Symptom Likely Cause
PK header missing, file size zero or truncated Storage failure
PK present, ZIP extraction fails Container damage
ZIP extracts cleanly, XML validation fails Structural damage
XML is valid, content missing or garbled in app Unsupported feature

If the signature is missing or garbled, you have a storage-layer problem. If the signature is intact but the file fails to open in Word or LibreOffice, the damage is inside the ZIP or XML structure. If the file opens but displays blank or incorrect content, you are likely dealing with an unsupported feature defined in the MS-DOCX specification.

Storage-Layer Recovery

If the file resides on a failing drive, copy it to healthy media using a tool that reads bad sectors, such as ddrescue on Linux or dd with conv=noerror. Do not attempt repair while the file sits on damaged media; you will compound the corruption.

Once copied, check the file size. A DOCX file smaller than 1 KB is almost certainly unrecoverable. The minimum ZIP container, including the required [Content_Types].xml entry, exceeds that size. Files between 1 KB and 10 KB may be partially recoverable if the PK header is intact, but expect data loss.

Repair action: If the PK header is missing but the file body is not empty, prepend the bytes 50 4B 03 04 14 00 00 00 00 00 00 00 to the beginning. This is the minimal ZIP local file header. Tools such as zip -F on Linux can then attempt to reconstruct the central directory from the local headers. This works only if the compressed XML data is still present after the header. If the file body contains only zeros or random noise, stop here.

Container Damage: ZIP Repair

A DOCX file is a ZIP archive containing XML files and media assets. The archive’s central directory—the table of contents at the end of the file—may be damaged even when the compressed data sections are intact. Run:

zip -FF corrupted.docx --out repaired.zip

This forces a scan of all local file headers and rebuilds the central directory. If successful, rename repaired.zip to repaired.docx. On Windows, 7-Zip can often extract partial archives: use 7z x corrupted.docx and inspect the output for missing or zero-length files.

Validation check: After extraction, confirm that [Content_Types].xml, word/document.xml, and _rels/.rels are present and non-empty. If word/document.xml is missing or contains only garbage bytes, the document body is unrecoverable.

Structural Damage: XML Repair

If the ZIP extracts fully, validate the XML. The critical file is word/document.xml. Open it in a text editor or an XML validator. Common structural errors include:

  • Unclosed tags (e.g., missing </w:p>)
  • Illegal characters (control characters outside the XML 1.0 allowed set: #x9, #xA, #xD, #x20–#xD7FF, #xE000–#xFFFD, #x10000–#x10FFFF)
  • Malformed namespace declarations (e.g., duplicate prefixes, missing URIs)

Repair action: For unclosed tags and recoverable syntax errors, use xmllint with the --recover flag:

xmllint --recover word/document.xml > word/document_fixed.xml

Replace the original file with the fixed version and re-zip the archive. When rebuilding, [Content_Types].xml and word/document.xml must be stored without compression; use -0 for those files in a manual rebuild. xmllint --recover drops malformed subtrees entirely. It will not restore missing content.

Hard limit: If word/document.xml contains illegal characters that xmllint cannot strip, or if the file is truncated mid-element, the document body is partially or fully lost. No tool can reconstruct semantic content from a broken XML tree.

Unsupported Features: Identification and Removal

Some DOCX files are structurally valid but contain features that a particular application cannot render. These are not corruption, but they prevent the file from opening or displaying correctly in non-Microsoft editors.

ActiveX Controls

ActiveX controls are embedded executables stored in word/activeX/. If the file opens in Word but not in LibreOffice, these objects are the cause. There is no repair—the feature is unsupported by the target application. Strip the activeX/ folder from the ZIP and remove the corresponding references in word/document.xml by searching for <w:object> elements with w:type="ActiveX".

Custom XML Parts

Some editors add proprietary data in word/customXml/. If the file fails to open in another application, delete the entire word/customXml/ folder and remove all <w:customXml> elements from word/document.xml. This data is not part of the visible document content.

Font Embedding

Fonts stored in word/embeddings/ are not corruption. Missing embedded fonts cause fallback rendering in the target application. No repair is needed.

MathML vs. OMML

Microsoft’s OMML (Office Math Markup Language) is not MathML. If your application supports only MathML, equations written in OMML will not render. This is a feature conversion, not a repair. Manual conversion or a dedicated transform is required.

Unrecoverable limit: If a file contains encrypted parts—password-protected sections or DRM-locked content defined at the container level in the specification—you cannot repair or bypass it without the encryption key. Any attempt to remove the encryption layer destroys the file.

Validate the Repair

After any repair, verify ZIP integrity:

unzip -t repaired.docx

Then validate word/document.xml against the DOCX schema. The official schema is available from the Microsoft Open Specifications (look for wml.xsd). A practical alternative is to open the file in Word’s “Open and Repair” mode, which rebuilds the document tree and discards non-standard elements, then save a new copy.

Unrecoverable States

Stop recovery attempts when any of these conditions are met:

  • File size is less than 1 KB.
  • The PK header is absent and the file body is all zeros or random noise.
  • The ZIP container has no valid local file headers (zip -FF returns zero entries).
  • word/document.xml is missing or contains only garbage bytes.

In these cases, the cost of recovery exceeds the value of the content. Prevent future loss by enabling version history in your document storage system.