From 75b8c58f25782e9799f1ff32ad6873d43843f801 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:18:54 +0800 Subject: [PATCH] fix(safe_browsing): rectify list update removal behavior --- src/safe_browsing/mod.rs | 13 ++++--------- src/safe_browsing/models.rs | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/safe_browsing/mod.rs b/src/safe_browsing/mod.rs index 4d05b6a..aadfe39 100644 --- a/src/safe_browsing/mod.rs +++ b/src/safe_browsing/mod.rs @@ -101,10 +101,8 @@ impl SafeBrowsing { for entry_set in &list_update.removals { if let Some(raw_indices) = &entry_set.raw_indices { - for index in &raw_indices.indices { - if (*index as usize) < current_prefixes.len() { - current_prefixes.remove(*index as usize); - } + for (idx_idx, idx) in raw_indices.indices.iter().enumerate() { + current_prefixes.remove(idx - idx_idx); } } } @@ -113,11 +111,8 @@ impl SafeBrowsing { if let Some(raw_hashes) = &entry_set.raw_hashes { let hashes = BASE64.decode(&raw_hashes.raw_hashes)?; - current_prefixes.extend( - hashes - .chunks(raw_hashes.prefix_size as usize) - .map(|c| c.to_vec()), - ); + current_prefixes + .extend(hashes.chunks(raw_hashes.prefix_size).map(|c| c.to_vec())); } } diff --git a/src/safe_browsing/models.rs b/src/safe_browsing/models.rs index f6b487e..d45b2c3 100644 --- a/src/safe_browsing/models.rs +++ b/src/safe_browsing/models.rs @@ -81,14 +81,14 @@ pub struct ThreatEntrySet { #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RawHashes { - pub prefix_size: u32, + pub prefix_size: usize, pub raw_hashes: String, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RawIndices { - pub indices: Vec, + pub indices: Vec, } #[derive(Debug, Clone, Serialize)]