From: joshuaruesweg Date: Fri, 12 Mar 2021 10:38:03 +0000 (+0100) Subject: Use random imageHash to avoid collisions X-Git-Tag: 5.4.0_Alpha_1~146^2~6 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e0a8b142e57430cd2541868fe35ac44c7588cda3;p=GitHub%2FWoltLab%2FWCF.git Use random imageHash to avoid collisions --- diff --git a/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php b/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php index 5345d247ba..b1a114f665 100644 --- a/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/UnfurlUrlBackgroundJob.class.php @@ -201,14 +201,17 @@ final class UnfurlUrlBackgroundJob extends AbstractBackgroundJob private function saveImage(array $imageData, string $image): string { - $imageHash = \sha1($image); + do { + $imageHash = StringUtil::getRandomID(); + + $path = WCF_DIR . UnfurlUrl::IMAGE_DIR . \substr($imageHash, 0, 2) . '/'; + } while (!empty(glob($path . $imageHash . '.*'))); - $path = WCF_DIR . UnfurlUrl::IMAGE_DIR . \substr($imageHash, 0, 2); FileUtil::makePath($path); $extension = $this->getImageExtension($imageData); - $fileLocation = $path . '/' . $imageHash . '.' . $extension; + $fileLocation = $path . $imageHash . '.' . $extension; \file_put_contents($fileLocation, $image);