microsoft / microsoft/markitdown
Base64 data URIs fail or decode incorrect bytes when their payload is percent-encoded
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 186k
- Forks
- 13.7k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 49
Description
Bug
On current main cc0ca9e, percent-encoded characters in a base64 data URI reach the base64 decoder without URL decoding. Some valid inputs raise binascii.Error; others silently produce incorrect bytes.
No network or fixture is needed (Python 3.12):
from markitdown._uri_utils import parse_data_uri
print(parse_data_uri("data:text/plain;base64,SGVsbG8%3D"))
# Expected: ('text/plain', {}, b'Hello')
# Actual: binascii.Error
print(parse_data_uri("data:application/octet-stream;base64,%2B/8="))
# Expected bytes: b'\xfb\xff'
# Actual bytes: b'\xd8\x1f\xfc'
MarkItDown.convert_uri also fails on URL-escaped base64 payloads. Raw base64 and non-base64 data URIs already work and should keep their behavior. RFC 2397 section 3 defines the data field using URL characters; decoding those escapes must precede base64 decoding. The new regression suite reports 16 failures and 2 passes against unchanged production code.
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 with parse_data_uri in markitdown._uri_utils and trace how MarkItDown.convert_uri handles data URIs. Run the regression cases described in the issue, then verify that percent-encoded base64 payloads decode to the expected bytes while raw base64 and non-base64 data URIs retain their existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100