Repository navigation
fix(email): strip trailing NUL characters from .msg properties and body - #5552
Conversation
|
✅ DCO Check Passed Thanks @DhyaanKanoja11, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
AI triage (advisory)Checked commit The PR strips trailing NUL characters from CI safety: no concern found. A maintainer must still approve CI. The |
I, Dhyaan Kanoja <[email protected]>, hereby add my Signed-off-by to this commit: 85aff28 Signed-off-by: Dhyaan Kanoja <[email protected]>
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 66629af553. It read the code and did not run it.
The changes correctly strip trailing NUL characters from Outlook .msg properties, headers, bodies, and attachment metadata in docling/backend/email_backend.py:287. I checked the header sanitization, attachment handling, body recovery fallbacks, and the regression test.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…cipients, attachments and body recovery Signed-off-by: Dhyaan Kanoja <[email protected]>
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the changes since 66629af553 at 2fa82d0ed1. It read the code and did not run it.
I found no defect in the new commit. The new test lines cover recipients, attachment names and MIME types, the HTML body, and the _recover_msg_body fallback. The test is mock-heavy, but the mocks are the only way to put NUL bytes into these properties.
A maintainer makes the merge decision. This review never approves the pull request.
Signed-off-by: Dhyaan Kanoja <[email protected]>
Add msg_8bit_nul_terminated.msg: msg_with_attachment.msg with every PtypString property stored as PtypString8, the ASCII text followed by NUL bytes, message code page 1252. The stream sizes are unchanged, so the file is a valid OLE file that python-oxmsg reads with the NUL bytes kept in every value. The new test converts it through DocumentConverter. On main, the title, body and attachment names keep the NUL bytes, and From: and To: are lost. With this fix, no NUL reaches the document and both headers are back. This covers the real python-oxmsg path, including the sender that python-oxmsg builds as "name\0" <address\0>. Signed-off-by: Daniel Nguyen <[email protected]>
DanielNg0729
left a comment
There was a problem hiding this comment.
Thanks @DhyaanKanoja11 for the fix, LGTM! I tested it with real-shaped files. On main, NUL bytes leak into the title, body and attachment names, and both From: and To: are lost. With this PR, all of them are clean. All email tests pass, also after a merge with current main.
To make it a bit more complete, I added one commit with a real fixture, msg_8bit_nul_terminated.msg. It is msg_with_attachment.msg with every string property stored as an 8-bit stream that ends with NUL bytes. The new test converts it through DocumentConverter, so it covers the real python-oxmsg path, including the sender that python-oxmsg builds as "Alice\x00" <[email protected]\x00>. It fails on main and passes here.
Thanks again!
Merged into current main, tests/test_backend_email.py has 1537 lines, over the 1500-line limit of the max-lines hook, so the lint check fails. Move the two NUL tests of this PR, unchanged, to tests/test_backend_email_msg_nul.py. Signed-off-by: Daniel Nguyen <[email protected]>
|
Thanks so much @DanielNg0729 for testing with real-shaped files and adding the \msg_8bit_nul_terminated.msg\ fixture! Really glad to see the end-to-end \DocumentConverter\ path covered and passing cleanly. Appreciate the review and support! |
…est (#5615) fix(tests): unpack the tuple from _msg_to_rfc822_bytes in the NUL test The NUL test from #5552 assigns the result of EmailDocumentBackend._msg_to_rfc822_bytes() to one name. #5420 changed the helper to return (rfc822_bytes, sender_fallback), so the test now passes a tuple to BytesIO and fails with a TypeError on main. Unpack the tuple, like the other callers do. Signed-off-by: Michele Dolfi <[email protected]>
Fixes #5535
What
Strip trailing NUL (
\x00) characters from string properties (subject, sender, recipients, attachment names, MIME types, and bodies) when converting Outlook.msgfiles inEmailDocumentBackend._msg_to_rfc822_bytesand_recover_msg_body.Why
In non-Unicode (8-bit)
.msgfiles,PtypString8streams are often null-terminated.python-oxmsgdecodes the full stream without trimming trailing null bytes, which causes:From:and recipient headers to fail parsing inmailparserwhen embedded null bytes are present, causing sender information to be omitted.\x00characters to leak into document text items and markdown exports.Changes
docling/backend/email_backend.py:_header_safeby stripping any\x00before splitting/folding headers.\x00fromsubject,sender, recipient names/addresses, attachments (file names, MIME types), and bodies (plain_body,html_body, and_recover_msg_body).tests/test_backend_email.py:test_msg_strips_trailing_nul_from_properties_and_bodyverifying that trailing null bytes do not leak into text elements or markdown exports and thatFrom:headers parse cleanly.