Skip to content

Commit f3a5bc8

Browse files
committed
fix: block writing empty files with 0 quota
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 829236f commit f3a5bc8

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

lib/private/Files/Storage/Wrapper/Quota.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,20 @@ public function copy(string $source, string $target): bool {
120120

121121
#[\Override]
122122
public function fopen(string $path, string $mode) {
123-
if (!$this->hasQuota()) {
123+
if (!$this->hasQuota() || $this->isPartFile($path)) {
124124
return $this->getWrapperStorage()->fopen($path, $mode);
125125
}
126-
$source = $this->getWrapperStorage()->fopen($path, $mode);
127126

128-
// don't apply quota for part files
129-
if (!$this->isPartFile($path)) {
130-
$free = $this->free_space($path);
131-
if ($source && (is_int($free) || is_float($free)) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
132-
// only apply quota for files, not metadata, trash or others
133-
if ($this->shouldApplyQuota($path)) {
134-
return \OC\Files\Stream\Quota::wrap($source, $free);
135-
}
127+
$free = $this->free_space($path);
128+
if ($this->shouldApplyQuota($path) && $free == 0) {
129+
return false;
130+
}
131+
132+
$source = $this->getWrapperStorage()->fopen($path, $mode);
133+
if ($source && (is_int($free) || is_float($free)) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
134+
// only apply quota for files, not metadata, trash or others
135+
if ($this->shouldApplyQuota($path)) {
136+
return \OC\Files\Stream\Quota::wrap($source, $free);
136137
}
137138
}
138139

tests/lib/Files/Storage/Wrapper/QuotaTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,10 @@ public function testNoTouchQuotaZero(): void {
229229
$instance = $this->getLimitedStorage(0.0);
230230
$this->assertFalse($instance->touch('foobar'));
231231
}
232+
233+
public function testNoFopenQuotaZero(): void {
234+
$instance = $this->getLimitedStorage(0.0);
235+
$fh = $instance->fopen('files/test.txt', 'w');
236+
$this->assertFalse($fh);
237+
}
232238
}

0 commit comments

Comments
 (0)