Skip to content

fix(ipynb): catch decoding exceptions in accepts() to prevent pipeline crashes on non-decodable application/json files - #2185

Closed
aoright (aoright) wants to merge 4 commits into
microsoft:mainfrom
aoright:fix-ipynb-decoding-crash
Closed

aoright (aoright) wants to merge 4 commits into
microsoft:mainfrom
aoright:fix-ipynb-decoding-crash

Conversation

@aoright

Copy link
Copy Markdown
Contributor

Description

Fixes #1894.

When converting files whose MIME type starts with application/json but contain non-ASCII/binary data (such as a French PDF containing UTF-8 characters that failed to decode using the system's default locale/ASCII codec, or other binary files), IpynbConverter.accepts() raises a UnicodeDecodeError or ValueError which propagates uncaught and crashes the entire conversion pipeline.

This PR wraps the decode() operation in IpynbConverter.accepts() inside a try/except (UnicodeDecodeError, ValueError, LookupError) block, returning False gracefully when the file is not decodable, instead of raising an exception.

Verification

  • Added a new unit test test_ipynb_converter_accepts_handling_decode_error to packages/markitdown/tests/test_module_misc.py.
  • Verified that the unit tests pass.

辰言 and others added 2 commits July 2, 2026 17:06
…e crashes on non-decodable application/json files

Signed-off-by: 辰言 <oncwnuIWp30GguOyJ615Fqj8H-yc@git.weixin.qq.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The added handler and test are behaviorally redundant with the existing broad exception handler.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Attempts to prevent notebook detection from crashing on undecodable JSON-like streams.

Changes:

  • Adds explicit decoding exception handling.
  • Adds a regression test for invalid UTF-8 bytes.
File summaries
File Description
_ipynb_converter.py Adds targeted decoding exception handling.
test_module_misc.py Tests rejection of undecodable input.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/markitdown/src/markitdown/converters/_ipynb_converter.py
@afourney

Copy link
Copy Markdown
Member

aoright (@aoright) please respond to microsoft-github-policy-service, above

@afourney

Copy link
Copy Markdown
Member

IpynbConverter.accepts() now safely rejects undecodable JSON through #1929. I’m closing this as superseded. Please reopen if a decoding exception still escapes on current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: IpynbConverter.accepts() raises UnicodeDecodeError on non-ASCII files (French PDFs, etc.)

3 participants