laminas-mime icon indicating copy to clipboard operation
laminas-mime copied to clipboard

fix: binary files as part are corrupted when stripping carriage returns

Open pgmillon opened this issue 2 years ago • 7 comments

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

When using a simple PNG binary as part of a message, the carriage return characters are ripped off, corrupting the binary. Not ripping the carriage return characters have an impact in the parts splitting that was updated to use preg_match + PREG_OFFSET_CAPTURE as a replacement to strpos. This was done the support either \r\n or \n with a regex rather than a more complex approach. Working with a binary file highlighted the line feed that is added while reading each part, this was removed too a/ to avoid binary corruption and b/ a mime with no line feed shouldn't magically have one when reading. A unit test was added to ensure further support of binaries.

pgmillon avatar Apr 04 '22 16:04 pgmillon

@pgmillon it's possible that this, being a bugfix, should go to 2.9.x

Ocramius avatar Apr 04 '22 16:04 Ocramius

Hi, I wasn't sure how you deal with bugfixes, sorry. If you pull bugfixes from "legacy" branches into the main branch or if you "backport" from main into legacy branches. I can update this PR for 2.9.x, as you prefer.

pgmillon avatar Apr 04 '22 16:04 pgmillon

We merge up from oldstable branches to latest branches.

Since the last release is 2.9.1, I'd expect this to land in 2.9.2, therefore 2.9.x target branch.

We don't merge regular bugs into older branches, since they need to be security issues, in order to qualify for that :)

EDIT: I changed the base branch, but your commit will need to probably be cherry-picked on top of that, and then force-pushed here, so extraneous commits are gone.

Ocramius avatar Apr 04 '22 16:04 Ocramius

Should be fine for 2.9.x now.

pgmillon avatar Apr 04 '22 16:04 pgmillon

Wait, I just found another bug : if the message sender uses \r\n to generate the message rather than just \n, then the splitMime is not working correctly and leaving a lonely \r.

pgmillon avatar Apr 04 '22 18:04 pgmillon

There we go : in my original fix I assumed sender's EOL was \n but when testing with a server that was using \r\n, I noticed the intend to prevent binaries corruption was not met because of a trailing \r. I added a sender EOL detection to fix the parts splitting which now works fine with binaries.

pgmillon avatar Apr 04 '22 19:04 pgmillon

Hi, any chance to get that fix merged ? I'm waiting for it to cut a new release of a library I work on. Thanks.

pgmillon avatar Apr 17 '22 05:04 pgmillon