microsoft / microsoft/markitdown
Office Open XML: Invalid Files Return Success with Error Message Instead of Exception
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 186k
- Forks
- 13.7k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 49
Description
When converting invalid DOCX, XLSX, or PPTX files, MarkItDown returns a successful result with the string "This is not a valid Office Open XML file." in text_content, rather than raising an exception. This behavior makes it difficult to distinguish between a successful conversion and a file format error.
Expected Behavior:Invalid or corrupted Office Open XML files should cause the converter to raise a specific exception (e.g., FileConversionException), not return a result with an error message in the content.
Actual Behavior: The conversion completes "successfully" and returns a DocumentConverterResult with text_content set to "This is not a valid Office Open XML file.".
Steps to Reproduce:
Attempt to convert a non-OOXML or corrupted DOCX/XLSX/PPTX file.
Observe that no exception is raised; instead, the result contains the error string.
Suggested Fix: After conversion, check if text_content matches the error string and raise an exception if so. Alternatively, ensure the underlying libraries raise on invalid files and propagate the exception.
Additional Context: This behavior appears consistent across all Office Open XML converters, possibly due to a shared dependency or error-handling pattern.
Workaround:
result = markitdown.convert_stream(stream=stream, file_extension=ext),
if result.text_content.strip() == "This is not a valid Office Open XML file.":
raise ...
return result.text_content
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the markitdown.convert_stream entry point and reproduce the behavior with an invalid or corrupted DOCX, XLSX, or PPTX file. Trace the shared Office Open XML conversion path and confirm that invalid input raises a specific exception instead of returning the error string in text_content; verify the result for all three formats.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100