Skip to content

Commit

Permalink
Properly check storage size against QUOTA_SIZE_LIMIT (fixes #12247)
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Jul 6, 2016
1 parent 23f5264 commit e252793
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 e252793

Please sign in to comment.