Skip to content

fix(files): extract extension from basename in ObjectStoreStorage::fopen - #64197

Open
Bytepie wants to merge 2 commits into
nextcloud:masterfrom
Bytepie:fix/objectstore-fopen-basename-ext
Open

fix(files): extract extension from basename in ObjectStoreStorage::fopen#64197
Bytepie wants to merge 2 commits into
nextcloud:masterfrom
Bytepie:fix/objectstore-fopen-basename-ext

Conversation

@Bytepie

@Bytepie Bytepie commented Sep 10, 2026

Copy link
Copy Markdown

Summary

Fixes an issue in ObjectStoreStorage::fopen() where the file extension is extracted using strrpos($path, '.') across the entire relative path instead of basename($path).

Problem

When an extensionless file is located inside a folder containing a dot (e.g. 0. Projects/Subfolder/hit), $ext is assigned the entire subpath string after the dot:

$ext = ". Projects/Subfolder/hit"

When TempManager::getTemporaryFile($ext) is called, directory separators are stripped:

/tmp/oc_tmp_<32_chars>. ProjectsSubfolderhit

How we encountered it

In our production case, a user had deeply nested folders with Cyrillic names. Because Linux's NAME_MAX limit is 255 bytes (and Cyrillic takes 2 bytes per character in UTF-8), the flattened filename easily exceeded 255 bytes, causing Linux to reject it with ENAMETOOLONG.

TempManager returned false, and fopen(false, $mode) crashed with:

ValueError: Path must not be empty

This fatal error killed the PHP process while the write lock was active, leaving behind orphaned exclusive locks in Redis.

Solution

  1. Use basename($path) when extracting the file extension in ObjectStoreStorage::fopen().
  2. Guard against false return from getTemporaryFile() before invoking fopen().
  3. Added unit test testFopenWriteInDottedDirectoryWithoutExtension to ObjectStoreStorageTest.php.

Tests

Tested against live Nextcloud container where I had this issue during migration of data from GlusterFS to S3 (Ceph), and verified with PHPUnit in nextcloud-docker-dev environment.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Signed-off-by: Umer Tahir <umertahir6@gmail.com>
@Bytepie
Bytepie requested a review from a team as a code owner September 10, 2026 17:11
@Bytepie
Bytepie requested review from Altahrim, leftybournes, salmart-dev and sorbaugh and removed request for a team September 10, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant