From f9fcde32abe1c3bca7d3ab036f34862c92b606c3 Mon Sep 17 00:00:00 2001 From: catch Date: Fri, 18 Dec 2020 09:45:37 +0000 Subject: [PATCH] Issue #3036494 by Berdir, alexpott, rgpublic, cilefen, kerasai, regilero: Race condition in ImageStyle::createDerivative() --- core/lib/Drupal/Core/File/FileSystem.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/File/FileSystem.php b/core/lib/Drupal/Core/File/FileSystem.php index e7e4c7a1947..8547f6e98fd 100644 --- a/core/lib/Drupal/Core/File/FileSystem.php +++ b/core/lib/Drupal/Core/File/FileSystem.php @@ -520,12 +520,22 @@ class FileSystem implements FileSystemInterface { } if (!is_dir($directory)) { + if (!($options & static::CREATE_DIRECTORY)) { + return FALSE; + } + // Let mkdir() recursively create directories and use the default // directory permissions. - if ($options & static::CREATE_DIRECTORY) { - return @$this->mkdir($directory, NULL, TRUE); + $success = @$this->mkdir($directory, NULL, TRUE); + if ($success) { + return TRUE; + } + // If the operation failed, check again if the directory was created + // by another process/server, only report a failure if not. In this case + // we still need to ensure the directory is writable. + if (!is_dir($directory)) { + return FALSE; } - return FALSE; } $writable = is_writable($directory);