Skip to content

Allow quota write streams with unknown free space#61706

Open
veryCrunchy wants to merge 1 commit into
nextcloud:masterfrom
veryCrunchy:fix/quota-writestream-unknown-free-space
Open

Allow quota write streams with unknown free space#61706
veryCrunchy wants to merge 1 commit into
nextcloud:masterfrom
veryCrunchy:fix/quota-writestream-unknown-free-space

Conversation

@veryCrunchy

@veryCrunchy veryCrunchy commented Jul 1, 2026

Copy link
Copy Markdown

Summary

This PR allows quota-wrapped writeStream() calls to proceed when the reported free space is unknown.

With S3 primary object storage and a finite user quota, chunked WebDAV uploads can fail while writing chunks to the DAV upload staging path under uploads/.... For upload staging paths, Quota::free_space() delegates to the wrapped storage. Object-store-backed storage can report free space as unknown, but Quota::writeStream() currently compares the known stream size directly against that value and can raise NotEnoughSpaceException even though the user's destination quota has enough available space.

This changes Quota::writeStream() to treat unknown free space consistently with other quota wrapper write paths such as file_put_contents(), copy(), copyFromStorage(), and moveFromStorage().

A regression test covers writing a known-size stream to an uploads/... path when the wrapped storage reports unknown free space.

AI assistance was used to help inspect logs, reason through the relevant code path, draft the regression test, and organize validation. I prepared this patch after reproducing the issue on an affected Nextcloud instance. After the fix was drafted and tested locally, I found the existing report in #61488 and linked this PR to that issue.

Validation performed:

./autotest.sh sqlite lib/Files/Storage/Wrapper/QuotaTest.php

Result:

OK, but some tests were skipped!
Tests: 115, Assertions: 506, Skipped: 1.

Manual validation was also performed against an affected Nextcloud instance with S3 primary storage and a finite user quota:

  • Chunked WebDAV upload failed before this patch with 413 Request Entity Too Large / Insufficient space.
  • Applying this one-line change allowed the same chunked WebDAV upload to complete successfully.
  • Previously queued rclone VFS cache uploads were able to proceed without new 413 Insufficient space errors after applying the fix.
  • Backport requested for stable34. I checked stable33, stable32, stable31, and stable30; those branches do not contain the Quota::writeStream() override with the vulnerable $size < $free comparison.

TODO

  • Maintainer review

Checklist

AI (if applicable)

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

@veryCrunchy veryCrunchy requested a review from a team as a code owner July 1, 2026 20:39
@veryCrunchy veryCrunchy requested review from ArtificialOwl, Copilot, icewind1991, leftybournes and salmart-dev and removed request for a team July 1, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes false NotEnoughSpaceException failures during quota-wrapped writeStream() writes when the underlying storage reports “unknown/unlimited” free space (negative sentinel), which particularly affects chunked WebDAV uploads to uploads/... on S3 primary storage.

Changes:

  • Update OC\Files\Storage\Wrapper\Quota::writeStream() to allow known-size writes when free_space() is negative (unknown/unlimited), aligning with other quota wrapper write paths.
  • Add a PHPUnit regression test covering a known-size stream write to an uploads/... path when the wrapped storage reports unknown free space.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/private/Files/Storage/Wrapper/Quota.php Treat negative free_space() as allowed in writeStream() to avoid false “insufficient space” on storages that can’t report free space.
tests/lib/Files/Storage/Wrapper/QuotaTest.php Adds regression coverage for writing a sized stream to uploads/... when wrapped storage reports unknown free space.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/lib/Files/Storage/Wrapper/QuotaTest.php
@veryCrunchy

Copy link
Copy Markdown
Author

/backport to stable34

Signed-off-by: veryCrunchy <me@verycrunchy.dev>
@veryCrunchy veryCrunchy force-pushed the fix/quota-writestream-unknown-free-space branch from c2fe550 to 93995b1 Compare July 1, 2026 20:49
@veryCrunchy veryCrunchy requested a review from Copilot July 1, 2026 20:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

3 participants