1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-20 04:31:24 +02:00

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 <oliver@olivervogel.com>

---------

Co-authored-by: Oliver Vogel <oliver@olivervogel.com>
This commit is contained in:
Nicos Panayides
2025-05-14 17:21:20 +03:00
committed by GitHub
parent ae61c580ae
commit 9659e761ca

View File

@@ -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))
);
}