Skip to content

fix(spec): use saturating_sub in snapshot summary to prevent overflow panic#2144

Open
drbothen wants to merge 1 commit intoapache:mainfrom
drbothen:fix/saturating-sub-overflow
Open

fix(spec): use saturating_sub in snapshot summary to prevent overflow panic#2144
drbothen wants to merge 1 commit intoapache:mainfrom
drbothen:fix/saturating-sub-overflow

Conversation

@drbothen
Copy link

Which issue does this PR close?

N/A — standalone bug fix.

What changes are included in this PR?

The update_totals function in snapshot_summary.rs performs new_total -= value on a u64. When removed > previous_total + added (which can happen if metadata summaries are inconsistent or after certain compaction flows), this causes a subtraction overflow panic in debug mode and wraps to a massive number in release mode.

This PR replaces the subtraction with saturating_sub, clamping the result to 0 instead.

Are these changes tested?

Yes — unit test test_update_totals_saturating_sub_no_panic covers the overflow scenario (removed=15, previous_total=10, added=1).

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

Comments