From 15191d0230f342b18ba723d3c3a5dfbba15562dc Mon Sep 17 00:00:00 2001 From: Devin R Date: Tue, 16 Jun 2020 18:07:13 -0400 Subject: [PATCH] crypto: Fix overflow in should_upload_keys, bail out if uploaded keys > max uploaded --- matrix_sdk_crypto/src/machine.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 6eceadfb..b1ed1088 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -215,6 +215,12 @@ impl OlmMachine { match &self.uploaded_signed_key_count { Some(count) => { let max_keys = self.account.max_one_time_keys().await as u64; + // If there are more keys already uploaded than max_key / 2 + // bail out returning false, this also avoids overflow. + if count.load(Ordering::Relaxed) > (max_keys / 2) { + return false; + } + let key_count = (max_keys / 2) - count.load(Ordering::Relaxed); key_count > 0 }