From e157160ba2f5753c7ceb796ff62d79b5dd23ea0e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 23 Oct 2026 14:17:30 +0200 Subject: [PATCH 1/2] Add Psalm taint analysis annotations Psalm's taint analysis can only follow untrusted data through this library if its docblocks say which parameters are sinks and which return values are sources. These annotations are docblock-only and have no effect at runtime. --- src/Image.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Image.php b/src/Image.php index ecfa512d..fe8f1da6 100644 --- a/src/Image.php +++ b/src/Image.php @@ -711,6 +711,8 @@ public static function findLoad(string $filename): ?string * @throws Exception * * @return Image A new Image. + * + * @psalm-taint-sink file $name */ public static function newFromFile( string $name, @@ -955,6 +957,8 @@ public static function newFromSource(Source $source, string $string_options = '' * @throws Exception * * @return void + * + * @psalm-taint-sink file $name */ public function writeToFile(string $name, array $options = []): void { From 575199af4b10d6d60e45484ff8a1cda2ffa254cb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 23 Oct 2026 15:19:22 +0200 Subject: [PATCH 2/2] Add file sinks to findLoad(), Source::newFromFile() and Target::newToFile() --- src/Image.php | 2 ++ src/Source.php | 2 ++ src/Target.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/Image.php b/src/Image.php index fe8f1da6..796928d8 100644 --- a/src/Image.php +++ b/src/Image.php @@ -692,6 +692,8 @@ private function callEnum( * @param string $filename The file to test. * * @return string|null The name of the load operation, or null. + * + * @psalm-taint-sink file $filename */ public static function findLoad(string $filename): ?string { diff --git a/src/Source.php b/src/Source.php index 2e8febd5..d450ed74 100644 --- a/src/Source.php +++ b/src/Source.php @@ -49,6 +49,8 @@ public static function newFromDescriptor(int $descriptor): self * * You can pass this source to (for example) @see Image::newFromSource() * @throws Exception + * + * @psalm-taint-sink file $filename */ public static function newFromFile(string $filename): self { diff --git a/src/Target.php b/src/Target.php index acf231d1..54f918f3 100644 --- a/src/Target.php +++ b/src/Target.php @@ -48,6 +48,8 @@ public static function newToDescriptor(int $descriptor): self * * You can pass this target to (for example) @see Image::writeToTarget() * @throws Exception + * + * @psalm-taint-sink file $filename */ public static function newToFile(string $filename): self {