Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe7ad81

Browse files
committed
base64_encoding inside PhpSerializer to avoid null characters
1 parent 9bcea2e commit fe7ad81

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testDecodingFailsWithBadClass()
5858
$serializer = new PhpSerializer();
5959

6060
$serializer->decode([
61-
'body' => 'O:13:"ReceivedSt0mp":0:{}',
61+
'body' => base64_encode('O:13:"ReceivedSt0mp":0:{}'),
6262
]);
6363
}
6464
}

src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ public function decode(array $encodedEnvelope): Envelope
3030
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".');
3131
}
3232

33-
return $this->safelyUnserialize($encodedEnvelope['body']);
33+
$serializeEnvelope = base64_decode($encodedEnvelope['body']);
34+
35+
if (false === $serializeEnvelope) {
36+
throw new MessageDecodingFailedException('The "body" key could not be base64 decoded.');
37+
}
38+
39+
return $this->safelyUnserialize($serializeEnvelope);
3440
}
3541

3642
/**
@@ -39,7 +45,7 @@ public function decode(array $encodedEnvelope): Envelope
3945
public function encode(Envelope $envelope): array
4046
{
4147
return [
42-
'body' => serialize($envelope),
48+
'body' => base64_encode(serialize($envelope)),
4349
];
4450
}
4551

0 commit comments

Comments
 (0)