Skip to content

fix(webserver): guard division by zero in downloads page percentages - #83

Merged
ngosang merged 1 commit into
amule-org:masterfrom
ngosang:fix/dload-div-by-zero
Jun 11, 2026
Merged

fix(webserver): guard division by zero in downloads page percentages#83
ngosang merged 1 commit into
amule-org:masterfrom
ngosang:fix/dload-div-by-zero

Conversation

@ngosang

@ngosang ngosang commented Jun 11, 2026

Copy link
Copy Markdown
Member

The downloads page of the default template computes two completion percentages with an unguarded division:

  • the per-file column divides size_done by the file size, which is zero for 0-byte files;
  • the totals row divides the completed sum by the accumulated total size, which stays at zero whenever the status/category filter matches no files (the row is printed as long as the unfiltered list is non-empty).

In the second case the page rendered "-nan%" in the Total row. Guard both expressions with a ternary that falls back to 0 when the divisor is zero, matching the style already used elsewhere in the template.

Verified against a running amuleweb: with downloads present the percentages are unchanged, and with a filter matching no files the totals row now shows "0 b (0%)" instead of "-nan%".

The downloads page of the default template computes two completion
percentages with an unguarded division:

- the per-file column divides size_done by the file size, which is zero
  for 0-byte files;
- the totals row divides the completed sum by the accumulated total
  size, which stays at zero whenever the status/category filter matches
  no files (the row is printed as long as the unfiltered list is
  non-empty).

In the second case the page rendered "-nan%" in the Total row. Guard
both expressions with a ternary that falls back to 0 when the divisor
is zero, matching the style already used elsewhere in the template.

Verified against a running amuleweb: with downloads present the
percentages are unchanged, and with a filter matching no files the
totals row now shows "0 b (0%)" instead of "-nan%".
@ngosang
ngosang merged commit 5fd327f into amule-org:master Jun 11, 2026
9 checks passed
@ngosang
ngosang deleted the fix/dload-div-by-zero branch June 11, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant