Skip to content

fix(disk): do not divide by zero on a filesystem with no capacity - #1062

Merged
kesselb merged 1 commit into
masterfrom
fix/disk-info-zero-capacity
Aug 2, 2026
Merged

kesselb merged 1 commit into
masterfrom
fix/disk-info-zero-capacity

Conversation

@karlitschek

@karlitschek karlitschek commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

getDiskInfo() computed the used percentage as used * 100 / Blocks, using the block count straight out of df with no guard. A filesystem reporting zero total blocks therefore raised DivisionByZeroError.

That is an Error rather than an Exception, so the catch (RuntimeException) around the df call did not stop it and nothing else in the chain did either: Os::getDiskData() and Os::getDiskInfo() just forward. The result was a 500 for the whole monitoring page and the whole /api/v1/diskdata response, not a single missing row.

Whether it triggers depends on the df implementation. coreutils hides zero-block filesystems unless asked with -a, but busybox df lists them, so this is reachable on Alpine based images — an nsfs mount from snapd is enough.

A filesystem with no capacity is now reported as 0% used, keeping the row rather than dropping it silently. The used figure is also clamped at zero, so a filesystem reporting more available than total can no longer produce a negative size and a negative percentage.

Both backends carried the identical expression and both are fixed. The FreeBSD one had no disk tests at all, so it gains its first.

Verified by running the new tests against the unfixed collectors: both error with DivisionByZeroError at Linux.php:229 and FreeBSD.php:209, and pass after the change. The existing expectations are untouched — a normal filesystem still reports 16.13%.

🤖 AI (if applicable)

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

The used percentage is only computed when `df` reports a block count, so a
filesystem with zero total blocks is listed at 0% instead of raising
DivisionByZeroError. That is an Error, not a RuntimeException, so nothing in
Os::getDiskData() caught it and the whole monitoring page and
/api/v1/diskdata answered 500. busybox df lists such filesystems — an nsfs
mount from snapd is enough — coreutils only with -a.

Used is clamped at zero as well, so a filesystem reporting more available
than total no longer produces a negative size and percentage.

Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com>
@kesselb
kesselb force-pushed the fix/disk-info-zero-capacity branch from 306f663 to b89f28f Compare August 2, 2026 21:08
@kesselb kesselb self-assigned this Aug 2, 2026
@kesselb kesselb added this to the Nextcloud 35 milestone Aug 2, 2026
@kesselb
kesselb enabled auto-merge August 2, 2026 21:10
@kesselb
kesselb merged commit 216c26d into master Aug 2, 2026
43 checks passed
@kesselb
kesselb deleted the fix/disk-info-zero-capacity branch August 2, 2026 21:11
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.

2 participants