From 9659e761caaa4a63b9a6996ef89ec877bc716ebc Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Wed, 14 May 2025 17:21:20 +0300 Subject: [PATCH] GIF detection: Only check the first 6 bytes of the input (#1441) * Only check the first 6 bytes of the input to reduce memory usage and speed up the detection * Update src/Drivers/AbstractDecoder.php Co-authored-by: Oliver Vogel --------- Co-authored-by: Oliver Vogel --- src/Drivers/AbstractDecoder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Drivers/AbstractDecoder.php b/src/Drivers/AbstractDecoder.php index 46567171..029761ba 100644 --- a/src/Drivers/AbstractDecoder.php +++ b/src/Drivers/AbstractDecoder.php @@ -22,9 +22,11 @@ abstract class AbstractDecoder implements DecoderInterface */ protected function isGifFormat(string $input): bool { + $head = substr($input, 0, 6); + return 1 === preg_match( "/^47494638(37|39)61/", - strtoupper(substr(bin2hex($input), 0, 32)) + strtoupper(bin2hex($head)) ); }