clippytool opened PR #14805 from clippytool:cache-cleanup-threshold-overflow to bytecodealliance:main:
Fixes https://github.com/bytecodealliance/wasmtime/issues/14804
CacheConfig::validatebounds the two*-limit-percent-if-deletingsettings to
0-100, but nothing boundsfile-count-soft-limitand
files-total-size-soft-limit, which are plainu64values. The cleanup task
computed the deletion threshold as
limit.checked_mul(percent as u64).unwrap() / 100, so a valid configuration
such asfile-count-soft-limit = "18446744073709551615"with70%panics with
called Option::unwrap() on a None valueas soon as the first cleanup runs. The
panic is on the cache worker thread, so the CLI keeps running with a
permanently dead cache worker.This computes the percentage without widening the type and without overflowing
any intermediate:value / 100 * percent + (value % 100) * percent / 100is
exactlyfloor(value * percent / 100), and neither term exceedsvaluefor
percent <= 100. Large soft limits stay usable as an "effectively unlimited"
setting, so no new bound is added to the validation.Tests:
test_percent_ofcross-checks the helper againstu128arithmetic for values
aroundu64::MAXand percentages from 0 to 100, including the case that used
to panic.
test_on_update_cleanup_max_soft_limitsruns the cleanup task withu64::MAX
soft limits and asserts that it neither panics nor deletes recognized cache
entries (unrecognized files are still removed). It calls
handle_on_cache_updatedirectly, because a panic on the worker thread would
otherwise hang the test harness.
clippytool requested dicej for a review on PR #14805.
clippytool requested wasmtime-core-reviewers for a review on PR #14805.
:thumbs_up: dicej submitted PR review.
:speech_balloon: dicej created PR review comment:
Nit: more parenthesis here would make this expression easier to read (e.g. to emphasize that it's
(value / 100) * percent ...rather thanvalue / (100 * percent) ...), rather than rely on implicit operator precedence and associativity.
clippytool updated PR #14805.
:memo: clippytool submitted PR review.
:speech_balloon: clippytool created PR review comment:
Good point, done in 305c0ee — both the expression and the formula in the doc
comment now spell out the grouping:(value / 100) * percent + ((value % 100) * percent) / 100No behavior change;
cargo test -p wasmtime-internal-cachestill passes
(24 lib + 1 integration test).
dicej added PR #14805 wasmtime-cache: Compute cleanup thresholds without overflowing to the merge queue.
:check: dicej merged PR #14805.
dicej removed PR #14805 wasmtime-cache: Compute cleanup thresholds without overflowing from the merge queue.
Last updated: Oct 31 2026 at 23:03 UTC