Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly check storage size against QUOTA_SIZE_LIMIT (fixes #12247) #12289

Merged
merged 1 commit into from Jul 7, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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);
@@ -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(());
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.