Skip to content

Commit e4b4a98

Browse files
committed
address potential overflow on bitshift in backoff_time
1 parent aa0f6db commit e4b4a98

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ impl BackgroundTask {
492492
fn backoff_time(&self) -> (bool, Duration) {
493493
let backoff_count: u64 = self.backoff_count.into();
494494
let backoff_time = if backoff_count >= 1 {
495-
Duration::from_millis(500 * (1 << (backoff_count - 1)))
495+
// make sure the shift amount does not exceed 63 for a u64
496+
let shift_amount = (backoff_count - 1).min(63);
497+
Duration::from_millis(500u64.checked_shl(shift_amount as u32).unwrap_or(u64::MAX))
496498
} else {
497499
Duration::from_millis(0)
498500
};

0 commit comments

Comments
 (0)