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 <[email protected]>
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.

1 participant