From 68bc22c1ca38803cb5be6970b71035f7ba1e643f Mon Sep 17 00:00:00 2001 From: Zlatoslav Desiatnikov Date: Tue, 24 Mar 2026 21:04:34 +0300 Subject: [PATCH 1/5] Fix plugin crash on large CodeGeneratorRequest input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace amphp's non-blocking ByteStream\buffer(ByteStream\getStdin()) with synchronous stream_get_contents(STDIN) to prevent premature EOF detection on pipe reads exceeding ~250KB. amphp's ReadableResourceStream sets STDIN to non-blocking mode and permanently closes the stream when feof() returns true — even transiently. On large pipe payloads that exceed the OS pipe buffer, fread() can drain the buffer faster than protoc writes, causing a spurious EOF (see amphp/byte-stream#47). Fixes thesis-php/protoc-plugin#19 --- src/Io/ReadStreamInput.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Io/ReadStreamInput.php b/src/Io/ReadStreamInput.php index 372492c..95ce132 100644 --- a/src/Io/ReadStreamInput.php +++ b/src/Io/ReadStreamInput.php @@ -4,7 +4,6 @@ namespace Thesis\Protoc\Io; -use Amp\ByteStream; use Thesis\Protoc\Exception\InvalidInput; use Thesis\Protoc\ReadInput; @@ -16,10 +15,12 @@ #[\Override] public function read(): string { - try { - return ByteStream\buffer(ByteStream\getStdin()); - } catch (ByteStream\BufferException $e) { - throw new InvalidInput($e->getMessage(), $e->getCode(), $e); + $contents = stream_get_contents(\STDIN); + + if ($contents === false) { + throw new InvalidInput('Failed to read from STDIN'); } + + return $contents; } } From 219d652de6691952d817a304d3799a513919fa9a Mon Sep 17 00:00:00 2001 From: Zlatoslav Desiatnikov Date: Tue, 24 Mar 2026 21:06:22 +0300 Subject: [PATCH 2/5] style: use a root namespace for stream_get_contents function --- src/Io/ReadStreamInput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Io/ReadStreamInput.php b/src/Io/ReadStreamInput.php index 95ce132..ca9b2ac 100644 --- a/src/Io/ReadStreamInput.php +++ b/src/Io/ReadStreamInput.php @@ -15,7 +15,7 @@ #[\Override] public function read(): string { - $contents = stream_get_contents(\STDIN); + $contents = \stream_get_contents(\STDIN); if ($contents === false) { throw new InvalidInput('Failed to read from STDIN'); From 7ba5db0cad1782b1d015b5830e1f04e8f4e12e1d Mon Sep 17 00:00:00 2001 From: Zlatoslav Desiatnikov Date: Tue, 24 Mar 2026 21:29:46 +0300 Subject: [PATCH 3/5] refactor: amphp/byte-stream dependency --- composer.json | 4 ---- src/Io/WriteStreamOutput.php | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 33311a3..e8ca03b 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "php": "^8.4", "ext-bcmath": "*", "ext-filter": "*", - "amphp/byte-stream": "^2.1", "nette/php-generator": "4.2.1", "thesis/package-version": "0.1.2", "thesis/protobuf": "^0.1.6", @@ -32,9 +31,6 @@ "phpunit/phpunit": "^12.4", "symfony/var-dumper": "^8.0" }, - "conflict": { - "revolt/event-loop": "<0.2.5" - }, "autoload": { "psr-4": { "Thesis\\Protoc\\": "src/" diff --git a/src/Io/WriteStreamOutput.php b/src/Io/WriteStreamOutput.php index 2a0cb89..f341dfa 100644 --- a/src/Io/WriteStreamOutput.php +++ b/src/Io/WriteStreamOutput.php @@ -4,7 +4,6 @@ namespace Thesis\Protoc\Io; -use Amp\ByteStream; use Thesis\Protoc\WriteOutput; /** @@ -15,6 +14,6 @@ #[\Override] public function write(string $buffer): void { - ByteStream\getStdout()->write($buffer); + \fwrite(\STDOUT, $buffer); } } From 4b51311c2f55b807bd3c1c453973474d2ed22016 Mon Sep 17 00:00:00 2001 From: Zlatoslav Desiatnikov Date: Tue, 24 Mar 2026 21:42:02 +0300 Subject: [PATCH 4/5] style: fix cs issues --- src/Io/ReadStreamInput.php | 2 +- src/Io/WriteStreamOutput.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Io/ReadStreamInput.php b/src/Io/ReadStreamInput.php index ca9b2ac..95ce132 100644 --- a/src/Io/ReadStreamInput.php +++ b/src/Io/ReadStreamInput.php @@ -15,7 +15,7 @@ #[\Override] public function read(): string { - $contents = \stream_get_contents(\STDIN); + $contents = stream_get_contents(\STDIN); if ($contents === false) { throw new InvalidInput('Failed to read from STDIN'); diff --git a/src/Io/WriteStreamOutput.php b/src/Io/WriteStreamOutput.php index f341dfa..272d00c 100644 --- a/src/Io/WriteStreamOutput.php +++ b/src/Io/WriteStreamOutput.php @@ -14,6 +14,6 @@ #[\Override] public function write(string $buffer): void { - \fwrite(\STDOUT, $buffer); + fwrite(\STDOUT, $buffer); } } From f104f464b205a846667dc02264e0700c02150fe1 Mon Sep 17 00:00:00 2001 From: Zlatoslav Desiatnikov Date: Tue, 24 Mar 2026 21:51:54 +0300 Subject: [PATCH 5/5] style: add native_constant_invocation to cs fixer config --- .php-cs-fixer.dist.php | 1 + 1 file changed, 1 insertion(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f1b7a74..ab45b70 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -23,6 +23,7 @@ new PhpCsFixerCodingStandard()->applyTo($config, [ 'heredoc_indentation' => false, + 'native_constant_invocation' => false, ]); return $config;