Skip to content

Commit 3b53e9a

Browse files
authored
Merge pull request #58615 from nextcloud/jtr/fix-s3-normalizePath-falsy
fix(s3): prevent "0" path from being treated as root
2 parents 987a52b + 2d39c5a commit 3b53e9a

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,21 @@ class AmazonS3 extends Common {
3232

3333
private LoggerInterface $logger;
3434

35-
public function needsPartFile(): bool {
36-
return false;
37-
}
38-
3935
/** @var CappedMemoryCache<array|false> */
4036
private CappedMemoryCache $objectCache;
41-
4237
/** @var CappedMemoryCache<bool> */
4338
private CappedMemoryCache $directoryCache;
44-
4539
/** @var CappedMemoryCache<array> */
4640
private CappedMemoryCache $filesCache;
4741

4842
private IMimeTypeDetector $mimeDetector;
49-
private ?bool $versioningEnabled = null;
5043
private ICache $memCache;
44+
private ?bool $versioningEnabled = null;
5145

5246
public function __construct(array $parameters) {
5347
parent::__construct($parameters);
5448
$this->parseParams($parameters);
49+
// @todo: using `key` here may be problematic with different authentication methods and/or key rotation...
5550
$this->id = 'amazon::external::' . md5($this->params['hostname'] . ':' . $this->params['bucket'] . ':' . $this->params['key']);
5651
$this->initCaches();
5752
$this->mimeDetector = Server::get(IMimeTypeDetector::class);
@@ -64,7 +59,7 @@ public function __construct(array $parameters) {
6459
private function normalizePath(string $path): string {
6560
$path = trim($path, '/');
6661

67-
if (!$path) {
62+
if ($path === '') {
6863
$path = '.';
6964
}
7065

@@ -704,6 +699,11 @@ public function hasUpdated(string $path, int $time): bool {
704699
}
705700
}
706701

702+
public function needsPartFile(): bool {
703+
// handled natively by the S3 backend/client integration
704+
return false;
705+
}
706+
707707
public function writeStream(string $path, $stream, ?int $size = null): int {
708708
if ($size === null) {
709709
$size = 0;

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function normalizePath(string $path): string {
130130
$path = str_replace('//', '/', $path);
131131

132132
// dirname('/folder') returns '.' but internally (in the cache) we store the root as ''
133-
if (!$path || $path === '.') {
133+
if ($path === '.') {
134134
$path = '';
135135
}
136136

tests/lib/Files/Storage/Storage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public static function fileNameProvider(): array {
116116
['file with space.txt'],
117117
['spéciäl fäile'],
118118
['test single\'quote.txt'],
119+
/*['0'],*/ // disabled until upstream aws-sdk is patched
120+
['#'],
121+
['%'],
122+
['%20'],
119123
];
120124
}
121125

@@ -127,6 +131,10 @@ public static function directoryProvider(): array {
127131
['folder with space'],
128132
['spéciäl földer'],
129133
['test single\'quote'],
134+
/*['0'],*/ // disabled until upstream aws-sdk is patched
135+
['#'],
136+
['%'],
137+
['%20'],
130138
];
131139
}
132140

0 commit comments

Comments
 (0)