Skip to content

Commit aa6695e

Browse files
chripclaude
andcommitted
fix(SecureViewService): handle fopen() returning false for non-existent paths
When shouldSecure() is called with tryOpen=true on a path that does not exist yet (e.g. a rename target or a files_versions snapshot path), the underlying fopen() call returns false. Calling fclose(false) on that value throws a TypeError in PHP 8, which propagates as an uncaught exception and aborts the entire DAV operation with HTTP 500. To reproduce: enable Secure View watermarking for a group, add your user to that group, then rename or overwrite any Office document. The rename fails immediately with HTTP 500 and the following error appears in nextcloud.log: fclose(): Argument #1 ($stream) must be of type resource, bool given in …/richdocuments/lib/Service/SecureViewService.php:37 Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d79b884 commit aa6695e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

lib/Service/SecureViewService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public function shouldSecure(string $path, IStorage $storage, bool $tryOpen = tr
3434
if ($tryOpen) {
3535
// pity… fopen() does not document any possible Exceptions
3636
$fp = $storage->fopen($path, 'r');
37+
if ($fp === false) {
38+
// File does not exist yet (e.g. rename target or version snapshot).
39+
// Assume the target will be in a secure context so that rename/copy
40+
// is not blocked by checkSourceAndTarget.
41+
return true;
42+
}
3743
fclose($fp);
3844
}
3945

0 commit comments

Comments
 (0)