Skip to content

Commit

Permalink
Auto merge of #12289 - nox:slate, r=Ms2ger
Browse files Browse the repository at this point in the history
Properly check storage size against QUOTA_SIZE_LIMIT (fixes #12247)

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12289)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jul 7, 2016
2 parents 5dae3cc + e252793 commit 32fa565
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions components/net/storage_thread.rs
Expand Up @@ -144,12 +144,15 @@ impl StorageManager {
value: String) {
let origin = self.origin_as_string(url);

let current_total_size = {
let (this_storage_size, other_storage_size) = {
let local_data = self.select_data(StorageType::Local);
let session_data = self.select_data(StorageType::Session);
let local_data_size = local_data.get(&origin).map_or(0, |&(total, _)| total);
let session_data_size = session_data.get(&origin).map_or(0, |&(total, _)| total);
local_data_size + session_data_size
match storage_type {
StorageType::Local => (local_data_size, session_data_size),
StorageType::Session => (session_data_size, local_data_size),
}
};

let data = self.select_data_mut(storage_type);
Expand All @@ -158,14 +161,14 @@ impl StorageManager {
}

let message = data.get_mut(&origin).map(|&mut (ref mut total, ref mut entry)| {
let mut new_total_size = current_total_size + value.as_bytes().len();
let mut new_total_size = this_storage_size + value.as_bytes().len();
if let Some(old_value) = entry.get(&name) {
new_total_size -= old_value.as_bytes().len();
} else {
new_total_size += name.as_bytes().len();
}

if new_total_size > QUOTA_SIZE_LIMIT {
if (new_total_size + other_storage_size) > QUOTA_SIZE_LIMIT {
return Err(());
}

Expand Down

0 comments on commit 32fa565

Please sign in to comment.