Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1016)

Unified Diff: net/disk_cache/simple/simple_index_file.cc

Issue 2878533002: SimpleCache: Tolerate weird file sizes when doing index recovery. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_index_file.cc
diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc
index d31d2446c60914b64c73039a77881804fcddc1fe..56344cf6c9e564f937fc1644f607f429facf3685 100644
--- a/net/disk_cache/simple/simple_index_file.cc
+++ b/net/disk_cache/simple/simple_index_file.cc
@@ -160,14 +160,29 @@ void ProcessEntryFile(SimpleIndex::EntrySet* entries,
SimpleIndex::EntrySet::iterator it = entries->find(hash_key);
base::CheckedNumeric<uint32_t> total_entry_size = size;
+ // When the entry size is nonsense we can't use it, since don't want to
+ // crash, but we actually do want to proceed with the entry in the index: if
+ // it's not in index, and is never accessed again, then the file will never
+ // get removed. So we just make something up; if it's unused it will get
pasko 2017/05/11 12:15:07 not really "never get removed", it will be removed
morlovich 2017/05/19 11:35:05 It would be never removed if we decided to skip ov
+ // kicked out eventually; if it's used we will either delete the file due to
+ // file format error, or set this correctly.
+ const int kPlaceHolderSizeWhenInvalid = 32768;
pasko 2017/05/11 12:15:07 I think it's worth mentioning that the entry size
morlovich 2017/05/19 11:35:05 OK, will tweak the comment to make it more explici
Maks Orlovich 2017/05/19 13:18:06 Hmm, thinking some more, maybe we should range-che
pasko 2017/05/19 14:38:07 ah, you are right. That basically brings us back t
Maks Orlovich 2017/05/19 15:09:58 True, that would save work, but the check is proba
+ if (!total_entry_size.IsValid()) {
+ LOG(WARNING) << "Invalid file size while restoring index from disk: "
+ << size << " on file:" << file_name;
+ }
+
if (it == entries->end()) {
SimpleIndex::InsertInEntrySet(
- hash_key, EntryMetadata(last_used_time, total_entry_size.ValueOrDie()),
+ hash_key,
+ EntryMetadata(last_used_time, total_entry_size.ValueOrDefault(
+ kPlaceHolderSizeWhenInvalid)),
entries);
} else {
// Summing up the total size of the entry through all the *_[0-1] files
total_entry_size += it->second.GetEntrySize();
- it->second.SetEntrySize(total_entry_size.ValueOrDie());
+ it->second.SetEntrySize(
+ total_entry_size.ValueOrDefault(kPlaceHolderSizeWhenInvalid));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698