imrpove code

This commit is contained in:
Dennis Eichhorn 2023-05-25 10:21:49 +00:00
parent 819734daca
commit 08ce435c7c

View File

@ -249,18 +249,21 @@ class UploadFile
$limit = -1; $limit = -1;
$fileName = ''; $fileName = '';
$nameWithoutExtension = empty($tempName) ? '' : \substr($tempName, 0, -\strlen($extension) - 1); $nameWithoutExtension = empty($tempName)
? ''
: (empty($extension)
? $tempName
: \substr($tempName, 0, -\strlen($extension) - 1)
);
do { do {
++$limit; ++$limit;
$sha = empty($nameWithoutExtension) ? \sha1($tempName . $rnd) : $nameWithoutExtension . (empty($rnd) ? '' : '_' . $rnd); $tempName = empty($nameWithoutExtension)
? \sha1($tempName . $rnd)
: $nameWithoutExtension . (empty($rnd) ? '' : '_' . $rnd);
if ($sha === false) { $tempName .= !empty($extension) ? '.' . $extension : '';
throw new \Exception('No file path could be found. Potential attack!'); $fileName = $tempName;
}
$sha .= '.' . $extension;
$fileName = $sha;
$rnd = (string) \mt_rand(); $rnd = (string) \mt_rand();
} while (\is_file($path . '/' . $fileName) && $limit < self::PATH_GENERATION_LIMIT); } while (\is_file($path . '/' . $fileName) && $limit < self::PATH_GENERATION_LIMIT);