Skip to content

Commit

Permalink
fix(safe_browsing): rectify list update removal behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Nov 18, 2024
1 parent 5ac6554 commit 75b8c58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
13 changes: 4 additions & 9 deletions src/safe_browsing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/safe_browsing/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
pub indices: Vec<usize>,
}

#[derive(Debug, Clone, Serialize)]
Expand Down

0 comments on commit 75b8c58

Please sign in to comment.