From 66ca61112dfae3ca5b10bdcadd0ab6d934f06d74 Mon Sep 17 00:00:00 2001 From: dsech Date: Mon, 18 Oct 2021 17:36:15 +0300 Subject: [PATCH] [Messenger] fix: TypeError in PhpSerializer::encode() Ensure a MessageDecodingFailedException is thrown when the string to be unserialized is an empty string. This happens because unserializing an empty string does not issue a PHP warning, and simply returns false. --- .../Transport/Serialization/PhpSerializerTest.php | 12 ++++++++++++ .../Transport/Serialization/PhpSerializer.php | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php index 96f4503c2eede..891683790ad47 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php @@ -53,6 +53,18 @@ public function testDecodingFailsWithBadFormat() ]); } + public function testDecodingFailsWithBadBase64Body() + { + $this->expectException(MessageDecodingFailedException::class); + $this->expectExceptionMessageMatches('/Could not decode/'); + + $serializer = new PhpSerializer(); + + $serializer->decode([ + 'body' => 'x', + ]); + } + public function testDecodingFailsWithBadClass() { $this->expectException(MessageDecodingFailedException::class); diff --git a/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php b/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php index 3a4804903c673..0516ee2f40292 100644 --- a/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php +++ b/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php @@ -58,6 +58,10 @@ public function encode(Envelope $envelope): array private function safelyUnserialize(string $contents) { + if ('' === $contents) { + throw new MessageDecodingFailedException('Could not decode an empty message using PHP serialization.'); + } + $signalingException = new MessageDecodingFailedException(sprintf('Could not decode message using PHP serialization: %s.', $contents)); $prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback'); $prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler, $signalingException) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy