From 86f62958baa7b6be6bdbe8297c99568a08603df4 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 2 Jun 2019 17:20:34 +0200 Subject: [PATCH] - fixed `OverflowException` for large JSON payload received over TCP Socket connections --- app/main/lib/socket/AbstractSocket.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/main/lib/socket/AbstractSocket.php b/app/main/lib/socket/AbstractSocket.php index f39c9804..90c79419 100644 --- a/app/main/lib/socket/AbstractSocket.php +++ b/app/main/lib/socket/AbstractSocket.php @@ -17,6 +17,12 @@ use Clue\React\NDJson; abstract class AbstractSocket implements SocketInterface { + /** + * max length for JSON data string + * -> throw OverflowException on exceed + */ + const JSON_DECODE_MAX_LENGTH = 65536 * 4; + /** * @var EventLoop\LoopInterface|null */ @@ -195,7 +201,7 @@ abstract class AbstractSocket implements SocketInterface { // new empty stream for processing JSON $stream = new Stream\ThroughStream(); - $streamDecoded = new NDJson\Decoder($stream, true); + $streamDecoded = new NDJson\Decoder($stream, true, 512, 0, self::JSON_DECODE_MAX_LENGTH); // promise get resolved on first emit('data') $promise = Promise\Stream\first($streamDecoded);