fix bug in re-serializing multipart mime with preamble#540
Conversation
|
I haven't really immersed myself in this to review fully, this is just a quick drive-by comment: since it sounds like the slice/range is off-by-one, should the struct capture different indices? I'm wondering if this is a sharp edge that should be fixed at source. |
|
You are right, it would be cleaner to work with proper indices in the struct. There's also a subtlety I noticed from RFC 2046:
Even though the code works, it deviates from the RFC's note. In this PR, I would also align this, at the cost of changing the I'll try to update the code so that we fix this issue where it originates. |
3b08076 to
2bc98b3
Compare
|
Hey @wez , thanks for your suggestion to fix the issue at the source! I chose to extract a function for multipart-mime parsing, which reduces the counter-arithmetic that led to an off-by-one error. In contrast to what I wrote earlier, I won't align the behavior to RFC 2046. The call chain involves other parts than just multipart-mime, and I want to keep this PR small. Let me know what you think about this approach! |
check_fix_conformancerewrites the message buffer, but introduces byte changes in the body part.This breaks DKIM.
Example (after parse + to_message_bytes):
Explanation
In
recursive_parse, raw_body starts one byte early (body_offset - 1) so the\n--{boundary}needle can match a boundary at the very start of the body. The preamble was then captured asraw_body.slice(0..first_boundary_pos), which:raw_body[0], the\nof the header/body separator thatwrite_messagealready emits itself -> a duplicated\nafter the blank line and\rof the\r\npreceding the first boundary (the\nis consumed by the needle and never re-emitted) ->\r\n--boundaryis rewritten as\r--boundary.