fix: avoid integer overflow in browser average interval/ease columns#5208
Draft
krMaynard wants to merge 1 commit into
Draft
fix: avoid integer overflow in browser average interval/ease columns#5208krMaynard wants to merge 1 commit into
krMaynard wants to merge 1 commit into
Conversation
The browser's average-interval column computed `intervals.iter().sum::<u32>() * 86400` in u32. Intervals are in days, so a single card with an interval beyond ~49,710 days (reachable via a large maximum-interval setting, "set due date", or add-ons) overflowed u32 - panicking in debug builds and rendering a wildly wrong span in release. The average-ease column had the same shape: `eases.iter().sum::<u16>()` overflows u16 once ~27 cards are averaged in notes mode. Extract the two averages into small helpers that accumulate in a wider type (u64 for intervals, u32 for eases), and add unit tests covering the overflow-triggering inputs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue (required)
Fixes #5207
Summary / motivation (required)
The browser's average-interval column computed
intervals.iter().sum::<u32>() * 86400inu32. Intervals are in days, so a single card with an interval beyond ~49,710 days (reachable via a large maximum-interval setting, "set due date", or add-ons) overflowedu32— panicking in debug builds and rendering a wildly wrong span in release.The average-ease column had the same shape:
eases.iter().sum::<u16>()overflowsu16once ~27 cards are averaged in notes mode.The fix extracts the two averages into small helpers that accumulate in a wider type (
u64for intervals,u32for eases).Steps to reproduce (required, use N/A if not applicable)
How to test (required)
Checklist (minimum)
./ninja checkor an equivalent relevant check locally.Details
Adds unit tests covering the overflow-triggering inputs for both helpers. The full CI workflow ran against this exact commit: https://github.com/krMaynard/anki-fork/actions/runs/30141307409
Build, lint, and testpassed on Linux, macOS, and Windows, andformatandminilintspassed. The workflow's only failure was the Linux SARIF upload step (Resource not accessible by integration), after the substantive Linux checks had passed.Before / after behavior (optional)
Before: overflow panic (debug) / garbage value (release) for large intervals or many-card ease averages. After: correct averages via wider accumulation.
Risk / compatibility / migration (optional)
Low risk; display-only computation in the browser table.
UI evidence (required for visual changes; otherwise N/A)
N/A (no visual layout change; corrects an incorrectly-computed cell value)
Scope