Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger] Fix transporting non-UTF8 payloads by encoding them using base 64 #39970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2021

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jan 25, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #33913
License MIT
Doc PR -

Replaces #33920

When using the Doctrine transport, sending emails with binary attachments currently requires a custom Messenger serializer because the "body" column is created for UTF-8 only.

In #33920, it is proposed to change the TEXT type to a BLOB. It leaves at least one problem unhandled: the conversion of existing messenger tables.

This PR takes a more conservative approach, by encoding messages to base 64, only if they are non-UTF8.

Compatibility with the existing format is preserved.

The drawback of this approach is that the size of eg email attachments is going to increase by 33% because of the extra encoding. I think this drawback is acceptable for 4.4, and that this PR is the most pragmatic way to make attachments just work.

@rimas-kudelis
Copy link

rimas-kudelis commented Jan 25, 2021

The drawback of this approach is that the size of eg email attachments is going to increase by 33% because of the extra encoding. I think this drawback is acceptable for 4.4, and that this PR is the most pragmatic way to make attachments just work.

When you wrote this, did you mean it will increase the size of our messages in the storage, or did you refer to emails that are later sent out? From the code it looks like the former, but your comment almost implies the latter.

@nicolas-grekas
Copy link
Member Author

it will increase the size of our messages in the storage

yes, that's what I meant.

@@ -29,6 +29,10 @@ public function decode(array $encodedEnvelope): Envelope
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".');
}

if (false === strpos($encodedEnvelope['body'], '}', -1)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this check a bit errorprone, what about wrapping the base64 encoded content or prefix it with a special key which we can check against later when retrieving the message?

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jan 25, 2021

Choose a reason for hiding this comment

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

I don't think it's error-prone: the php serialization format is likely more stable than this very class.

@fabpot
Copy link
Member

fabpot commented Jan 25, 2021

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 43eb050 into symfony:4.4 Jan 25, 2021
@nicolas-grekas nicolas-grekas deleted the messenger-non-utf8 branch January 27, 2021 12:53
This was referenced Jan 27, 2021
@sroze
Copy link
Contributor

sroze commented Jan 28, 2021

Nice change @nicolas-grekas !

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

Successfully merging this pull request may close these issues.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.