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

Side by Side Diff: base/metrics/persistent_memory_allocator.cc

Issue 1654053002: New test and off-by-one fix for data persisted to disk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "base/metrics/persistent_memory_allocator.h" 5 #include "base/metrics/persistent_memory_allocator.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 return std::min(shared_meta()->freeptr.load(), mem_size_); 267 return std::min(shared_meta()->freeptr.load(), mem_size_);
268 } 268 }
269 269
270 size_t PersistentMemoryAllocator::GetAllocSize(Reference ref) const { 270 size_t PersistentMemoryAllocator::GetAllocSize(Reference ref) const {
271 const volatile BlockHeader* const block = GetBlock(ref, 0, 0, false, false); 271 const volatile BlockHeader* const block = GetBlock(ref, 0, 0, false, false);
272 if (!block) 272 if (!block)
273 return 0; 273 return 0;
274 uint32_t size = block->size; 274 uint32_t size = block->size;
275 // Header was verified by GetBlock() but a malicious actor could change 275 // Header was verified by GetBlock() but a malicious actor could change
276 // the value between there and here. Check it again. 276 // the value between there and here. Check it again.
277 if (size <= sizeof(BlockHeader) || ref + size >= mem_size_) { 277 if (size <= sizeof(BlockHeader) || ref + size > mem_size_) {
278 SetCorrupt(); 278 SetCorrupt();
279 return 0; 279 return 0;
280 } 280 }
281 return size - sizeof(BlockHeader); 281 return size - sizeof(BlockHeader);
282 } 282 }
283 283
284 uint32_t PersistentMemoryAllocator::GetType(Reference ref) const { 284 uint32_t PersistentMemoryAllocator::GetType(Reference ref) const {
285 const volatile BlockHeader* const block = GetBlock(ref, 0, 0, false, false); 285 const volatile BlockHeader* const block = GetBlock(ref, 0, 0, false, false);
286 if (!block) 286 if (!block)
287 return 0; 287 return 0;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() { 661 FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() {
662 } 662 }
663 663
664 // static 664 // static
665 bool FilePersistentMemoryAllocator::IsFileAcceptable( 665 bool FilePersistentMemoryAllocator::IsFileAcceptable(
666 const MemoryMappedFile& file) { 666 const MemoryMappedFile& file) {
667 return IsMemoryAcceptable(file.data(), file.length(), 0, true); 667 return IsMemoryAcceptable(file.data(), file.length(), 0, true);
668 } 668 }
669 669
670 } // namespace base 670 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698