From f6f91375e004a7fa89f059fbcfc41a766a501ae0 Mon Sep 17 00:00:00 2001 From: Umer Tahir Date: Thu, 10 Sep 2026 19:39:25 +0500 Subject: [PATCH] fix(files): extract extension from basename in ObjectStoreStorage::fopen Signed-off-by: Umer Tahir --- .../Files/ObjectStore/ObjectStoreStorage.php | 11 +++++++++-- .../Files/ObjectStore/ObjectStoreStorageTest.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 58359787f5769..4fa62747d1acb 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -304,8 +304,9 @@ public function filetype(string $path): string|false { public function fopen(string $path, string $mode) { $path = $this->normalizePath($path); - if (strrpos($path, '.') !== false) { - $ext = substr($path, strrpos($path, '.')); + $baseName = basename($path); + if (strrpos($baseName, '.') !== false) { + $ext = substr($baseName, strrpos($baseName, '.')); } else { $ext = ''; } @@ -366,6 +367,9 @@ public function fopen(string $path, string $mode) { } $tmpFile = Server::get(ITempManager::class)->getTemporaryFile($ext); + if ($tmpFile === false) { + return false; + } $handle = fopen($tmpFile, $mode); return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile): void { $this->writeBack($tmpFile, $path); @@ -380,6 +384,9 @@ public function fopen(string $path, string $mode) { case 'c': case 'c+': $tmpFile = Server::get(ITempManager::class)->getTemporaryFile($ext); + if ($tmpFile === false) { + return false; + } if ($this->file_exists($path)) { $source = $this->fopen($path, 'r'); file_put_contents($tmpFile, $source); diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php index c896eb377978c..74143d8d057e8 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php @@ -261,4 +261,19 @@ public function testCopyFolderSize(): void { $this->assertEquals(3, $cache->get('target')->getSize()); } + + public function testFopenWriteInDottedDirectoryWithoutExtension(): void { + $dir = '0. Folder.With.Dots/Subfolder'; + $this->instance->mkdir($dir); + + $filePath = $dir . '/extensionlessfile'; + $handle = $this->instance->fopen($filePath, 'w'); + $this->assertIsResource($handle); + + fwrite($handle, 'sample content'); + fclose($handle); + + $this->assertTrue($this->instance->file_exists($filePath)); + $this->assertEquals('sample content', $this->instance->file_get_contents($filePath)); + } }