Skip to content

Commit d3fe082

Browse files
susnuxbackportbot[bot]
authored andcommitted
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]>
1 parent 15726db commit d3fe082

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ public function put($data) {
127127
$view = Filesystem::getView();
128128

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

133134
if (!$view->isCreatable($partFilePath) && $view->isUpdatable($this->path)) {
134135
$needsPartFile = false;
@@ -375,9 +376,14 @@ public function put($data) {
375376
private function getPartFileBasePath($path) {
376377
$partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true);
377378
if ($partFileInStorage) {
378-
return $path;
379+
$filename = basename($path);
380+
// hash does not need to be secure but fast and semi unique
381+
$hashedFilename = hash('xxh128', $filename);
382+
return substr($path, 0, strlen($path) - strlen($filename)) . $hashedFilename;
379383
} else {
380-
return md5($path); // will place it in the root of the view with a unique name
384+
// will place the .part file in the users root directory
385+
// therefor we need to make the name (semi) unique - hash does not need to be secure but fast.
386+
return hash('xxh128', $path);
381387
}
382388
}
383389

build/integration/dav_features/dav-v2.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ Feature: dav-v2
108108
When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
109109
Then the HTTP status code should be "201"
110110

111+
Scenario: Uploading a file with very long filename
112+
Given using new dav path
113+
And As an "admin"
114+
And user "user0" exists
115+
And user "user0" has a quota of "10 MB"
116+
And As an "user0"
117+
When User "user0" uploads file "data/textfile.txt" to "/long-filename-with-250-characters-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.txt"
118+
Then the HTTP status code should be "201"
119+
120+
Scenario: Uploading a file with a too long filename
121+
Given using new dav path
122+
And As an "admin"
123+
And user "user0" exists
124+
And user "user0" has a quota of "10 MB"
125+
And As an "user0"
126+
When User "user0" uploads file "data/textfile.txt" to "/long-filename-with-251-characters-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.txt"
127+
Then the HTTP status code should be "400"
128+
111129
Scenario: Create a search query on image
112130
Given using new dav path
113131
And As an "admin"
@@ -132,3 +150,14 @@ Feature: dav-v2
132150
Then Favorite search should work
133151
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
134152

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

0 commit comments

Comments
 (0)