Skip to content

Commit fd7438a

Browse files
Merge pull request #52767 from nextcloud/backport/52686/stable31
[stable31] fix(files_external): Safely check if the timestamp is numeric
2 parents 6be6a66 + 0eeb833 commit fd7438a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

apps/files_external/lib/Lib/Storage/Swift.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ public function opendir(string $path) {
285285

286286
public function stat(string $path): array|false {
287287
$path = $this->normalizePath($path);
288-
289288
if ($path === '.') {
290289
$path = '';
291290
} elseif ($this->is_dir($path)) {
@@ -305,22 +304,23 @@ public function stat(string $path): array|false {
305304
return false;
306305
}
307306

308-
$dateTime = $object->lastModified ? \DateTime::createFromFormat(\DateTime::RFC1123, $object->lastModified) : false;
309-
$mtime = $dateTime ? $dateTime->getTimestamp() : null;
310-
$objectMetadata = $object->getMetadata();
311-
if (isset($objectMetadata['timestamp'])) {
312-
$mtime = $objectMetadata['timestamp'];
307+
$mtime = null;
308+
if (!empty($object->lastModified)) {
309+
$dateTime = \DateTime::createFromFormat(\DateTime::RFC1123, $object->lastModified);
310+
if ($dateTime !== false) {
311+
$mtime = $dateTime->getTimestamp();
312+
}
313313
}
314314

315-
if (!empty($mtime)) {
316-
$mtime = floor($mtime);
315+
if (is_numeric($object->getMetadata()['timestamp'] ?? null)) {
316+
$mtime = (float)$object->getMetadata()['timestamp'];
317317
}
318318

319-
$stat = [];
320-
$stat['size'] = (int)$object->contentLength;
321-
$stat['mtime'] = $mtime;
322-
$stat['atime'] = time();
323-
return $stat;
319+
return [
320+
'size' => (int)$object->contentLength,
321+
'mtime' => isset($mtime) ? (int)floor($mtime) : null,
322+
'atime' => time(),
323+
];
324324
}
325325

326326
public function filetype(string $path) {

0 commit comments

Comments
 (0)