From bb1129c209c67049bfb2fc51112d93db0e2bbba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 3 Nov 2026 16:44:42 +0100 Subject: [PATCH] fix(FileStream): improve stream validation in constructor Ensure the stream is readable and metadata is correctly checked. --- src/Lib/ValueObjects/FileStream.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Lib/ValueObjects/FileStream.php b/src/Lib/ValueObjects/FileStream.php index 0c5de79..1755039 100644 --- a/src/Lib/ValueObjects/FileStream.php +++ b/src/Lib/ValueObjects/FileStream.php @@ -20,8 +20,11 @@ final readonly class FileStream throw new UnexpectedStorageException('Resource is not a valid stream.'); } - if (! stream_get_meta_data($this->resource)) { - throw new UnexpectedStorageException('Unable to read stream metadata.'); + $meta = stream_get_meta_data($this->resource); + $mode = $meta['mode']; + + if (! str_contains($mode, 'r') && ! str_contains($mode, '+')) { + throw new UnexpectedStorageException('Stream is not readable.'); } } @@ -66,7 +69,7 @@ final readonly class FileStream } $meta = stream_get_meta_data($this->resource); - if ($meta['seekable'] ?? false) { + if ($meta['seekable']) { rewind($this->resource); }