[stable10] Prevent endless loop in \OC\Files\View::createParentDirectories
\OC\Files\View::createParentDirectories was previously prone to an endless loop. If a path such as /foo/existingfile.txt/bar/foo was passed and existingfile.txt existed in foo the loop was never left and running until the PHP process timed out. This commit changes the logic to a foreach loop over an array and additionally additional error handling using is_file. Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
parent
db2206450f
commit
072794d78d
|
@ -2120,14 +2120,19 @@ class View {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function createParentDirectories($filePath) {
|
private function createParentDirectories($filePath) {
|
||||||
$parentDirectory = dirname($filePath);
|
$directoryParts = explode('/', $filePath);
|
||||||
while(!$this->file_exists($parentDirectory)) {
|
$directoryParts = array_filter($directoryParts);
|
||||||
$result = $this->createParentDirectories($parentDirectory);
|
foreach($directoryParts as $key => $part) {
|
||||||
if($result === false) {
|
$currentPathElements = array_slice($directoryParts, 0, $key);
|
||||||
|
$currentPath = '/' . implode('/', $currentPathElements);
|
||||||
|
if($this->is_file($currentPath)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(!$this->file_exists($currentPath)) {
|
||||||
|
$this->mkdir($currentPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->mkdir($filePath);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue