Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(dav): allow uploading of files with long filenames
A filename must be less or equal 255 characters, but when adding the
`.part` and `.ocfiletransfer` extensions we might overflow this limit.
So we should also use filename hashes for uploading when the file has a
long filename, similar like when we are uploading to the user storage
directly.

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Apr 22, 2025
commit b4255a96529ac1ac61b84170bd5965f3fe07a979
12 changes: 9 additions & 3 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ public function put($data) {
$view = Filesystem::getView();

if ($needsPartFile) {
$transferId = \rand();
// mark file as partial while uploading (ignored by the scanner)
$partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part';
$partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . $transferId . '.part';

if (!$view->isCreatable($partFilePath) && $view->isUpdatable($this->path)) {
$needsPartFile = false;
Expand Down Expand Up @@ -377,9 +378,14 @@ public function put($data) {
private function getPartFileBasePath($path) {
$partFileInStorage = Server::get(IConfig::class)->getSystemValue('part_file_in_storage', true);
if ($partFileInStorage) {
return $path;
$filename = basename($path);
// hash does not need to be secure but fast and semi unique
$hashedFilename = hash('xxh128', $filename);
return substr($path, 0, strlen($path) - strlen($filename)) . $hashedFilename;
} else {
return md5($path); // will place it in the root of the view with a unique name
// will place the .part file in the users root directory
// therefor we need to make the name (semi) unique - hash does not need to be secure but fast.
return hash('xxh128', $path);
}
}

Expand Down
29 changes: 29 additions & 0 deletions build/integration/dav_features/dav-v2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ Feature: dav-v2
When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
Then the HTTP status code should be "201"

Scenario: Uploading a file with very long filename
Given using new dav path
And As an "admin"
And user "user0" exists
And user "user0" has a quota of "10 MB"
And As an "user0"
When User "user0" uploads file "data/textfile.txt" to "/long-filename-with-250-characters-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.txt"
Then the HTTP status code should be "201"

Scenario: Uploading a file with a too long filename
Given using new dav path
And As an "admin"
And user "user0" exists
And user "user0" has a quota of "10 MB"
And As an "user0"
When User "user0" uploads file "data/textfile.txt" to "/long-filename-with-251-characters-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.txt"
Then the HTTP status code should be "400"

Scenario: Create a search query on image
Given using new dav path
And As an "admin"
Expand All @@ -132,3 +150,14 @@ Feature: dav-v2
Then Favorite search should work
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"

Scenario: Create a search query on favorite
Given using new dav path
And As an "admin"
And user "user0" exists
And As an "user0"
When User "user0" uploads file "data/green-square-256.png" to "/fav_image.png"
Then Favorite search should work
And the response should be empty
When user "user0" favorites element "/fav_image.png"
Then Favorite search should work
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
Loading