OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/disk_cache/block_files.h" | 5 #include "net/disk_cache/block_files.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 MappedFile* file = new MappedFile(); | 240 MappedFile* file = new MappedFile(); |
241 file->AddRef(); | 241 file->AddRef(); |
242 | 242 |
243 if (!file->Init(name, kBlockHeaderSize)) { | 243 if (!file->Init(name, kBlockHeaderSize)) { |
244 NOTREACHED(); | 244 NOTREACHED(); |
245 LOG(ERROR) << "Failed to open " << name; | 245 LOG(ERROR) << "Failed to open " << name; |
246 file->Release(); | 246 file->Release(); |
247 return false; | 247 return false; |
248 } | 248 } |
249 | 249 |
| 250 if (file->GetLength() < static_cast<size_t>(kBlockHeaderSize)) { |
| 251 LOG(ERROR) << "File too small " << name; |
| 252 file->Release(); |
| 253 return false; |
| 254 } |
| 255 |
250 block_files_[index] = file; | 256 block_files_[index] = file; |
251 | 257 |
252 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer()); | 258 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer()); |
253 if (kBlockMagic != header->magic || kCurrentVersion != header->version) { | 259 if (kBlockMagic != header->magic || kCurrentVersion != header->version) { |
254 LOG(ERROR) << "Invalid file version or magic"; | 260 LOG(ERROR) << "Invalid file version or magic"; |
255 return false; | 261 return false; |
256 } | 262 } |
257 | 263 |
258 if (header->updating) { | 264 if (header->updating) { |
259 // Last instance was not properly shutdown. | 265 // Last instance was not properly shutdown. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 int num_entries = (file_size - sizeof(*header)) / header->entry_size; | 485 int num_entries = (file_size - sizeof(*header)) / header->entry_size; |
480 header->max_entries = num_entries; | 486 header->max_entries = num_entries; |
481 } | 487 } |
482 | 488 |
483 FixAllocationCounters(header); | 489 FixAllocationCounters(header); |
484 header->updating = 0; | 490 header->updating = 0; |
485 return true; | 491 return true; |
486 } | 492 } |
487 | 493 |
488 } // namespace disk_cache | 494 } // namespace disk_cache |
OLD | NEW |