Selaa lähdekoodia

Fix for GD and animated WebP

Visman 2 vuotta sitten
vanhempi
commit
76baacb67a
1 muutettua tiedostoa jossa 21 lisäystä ja 1 poistoa
  1. 21 1
      app/Core/Image/GDDriver.php

+ 21 - 1
app/Core/Image/GDDriver.php

@@ -27,7 +27,11 @@ class GDDriver extends DefaultDriver
 
     public function readFromStr(string $data): mixed
     {
-        return $this->tuning($this->ready ? \imagecreatefromstring($data) : false);
+        if ($this->isBadData(\substr($data, 0, 64))) {
+            return false;
+        } else {
+            return $this->tuning($this->ready ? \imagecreatefromstring($data) : false);
+        }
     }
 
     public function readFromPath(string $path): mixed
@@ -35,6 +39,7 @@ class GDDriver extends DefaultDriver
         if (
             ! $this->ready
             || $this->files->isBadPath($path)
+            || $this->isBadData(\file_get_contents($path, false, null, 0, 64))
         ) {
             return false;
         } else {
@@ -42,6 +47,21 @@ class GDDriver extends DefaultDriver
         }
     }
 
+    protected function isBadData(string $data): bool
+    {
+        if (
+            8 === \strpos($data, 'WEBP')
+            && (
+                \strpos($data, 'ANIM')
+                || \strpos($data, 'ANMF')
+            )
+        ) {
+            return true;
+        }
+
+        return false;
+    }
+
     protected function tuning(mixed $image): mixed
     {
         if (