Skip to content

Conversation

@joshtrichards
Copy link
Member

  • Resolves: #tbd/na

Summary

Discovered while investigating random failures in the QuotaTest unit test.

The problem:

  • $size is set to the length of $data after truncation.
  • The quota ($this->limit) is decremented by $size before the actual write.
  • The function returns the result of fwrite(), which may be more or less than $size.

If fwrite() writes fewer bytes than $size (e.g., disk full), the quota will still be reduced by $size, not the actual number written.

Similarly, if it writes more (for example, if the underlying buffer had data in it), the returned value will be higher than expected.

The fix:

  • The quota is now decremented by the actual number of bytes written ($written) rather than the intended size.
  • This ensures quota tracking stays accurate even if fwrite writes fewer (or more, due to underlying buffering) bytes than requested.

TODO

  • It's possible there are other spots with similar behavior; should be checked and followed up on separately as needed
  • Backport?

Checklist

The quota is now decremented by the actual number of bytes written ($written) rather than the intended size.

This ensures quota tracking stays accurate even if fwrite writes fewer (or more - i.e. from underlying buffering/etc) bytes than requested.

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Oct 14, 2025
@joshtrichards joshtrichards marked this pull request as ready for review October 14, 2025 11:53
@joshtrichards joshtrichards requested a review from a team as a code owner October 14, 2025 11:53
@joshtrichards joshtrichards requested review from ArtificialOwl and yemkareems and removed request for a team October 14, 2025 11:53
@joshtrichards joshtrichards added this to the Nextcloud 33 milestone Oct 14, 2025
@susnux susnux merged commit 48378ae into master Oct 14, 2025
199 of 201 checks passed
@susnux susnux deleted the jtr/fix-files-stream-quota-actual branch October 14, 2025 11:56
@nextcloud-bot nextcloud-bot mentioned this pull request Jan 6, 2026
joshtrichards added a commit that referenced this pull request Jan 10, 2026
Refactors Quota stream logic so that quota is only decremented when writes grow the file, not on overwrites, reads, or seeks. This ensures quota enforcement is robust and matches expected storage semantics. Adds extra safety checks after writing to prevent quota drift.

Follow-up to #55731

Signed-off-by: Josh <josh.t.richards@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants