summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-28 19:30:05 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-28 19:30:05 +0000
commitb475f4e83d97a30434241a843e1fc67ac4b9bbf6 (patch)
treed76024cd376e34004de2ae15e1dc848941cb0d17 /net/disk_cache
parent518ab06be60c5719087b880aa646f519dc745150 (diff)
downloadchromium_src-b475f4e83d97a30434241a843e1fc67ac4b9bbf6.zip
chromium_src-b475f4e83d97a30434241a843e1fc67ac4b9bbf6.tar.gz
chromium_src-b475f4e83d97a30434241a843e1fc67ac4b9bbf6.tar.bz2
Crash when we notice a corruption of the histogram range-vector
The range vector is calculated once when a histogram is constructed, and should never change over the lifetime of the histogram. When it does change, it means that memory is being overwritten. We now crash (via CHECK) when there is any detected corruption of the range vector. This CL uses a more robust check-sum algorithm to detect corruption of the vector. The previous algorithm just did a sum, and was too easilly tricked by small (offsetting) changes in several ranges. Hopefully, this CRC-32 implementation will not be so easilly fooled. I had to refactor the class to ensure that each histogram was completely constructed before I registered it. The old code could sometimes register a base class (tradtional Histogram, with exponential bucket spread) and then run the derived constructor (such as when creating a LinearHistogram, with a second construction of the ranges and checksum). I now carefully avoid generating the checksum until fully constructing the instance, and then I run InitializeBuckets only once on the instance before registering it. bug=73939 r=mbelshe Review URL: http://codereview.chromium.org/6577013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76239 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/stats_histogram.cc19
-rw-r--r--net/disk_cache/stats_histogram.h1
2 files changed, 14 insertions, 6 deletions
diff --git a/net/disk_cache/stats_histogram.cc b/net/disk_cache/stats_histogram.cc
index 39c9056..028ae17 100644
--- a/net/disk_cache/stats_histogram.cc
+++ b/net/disk_cache/stats_histogram.cc
@@ -32,12 +32,11 @@ scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet(
if (StatisticsRecorder::FindHistogram(name, &histogram)) {
DCHECK(histogram.get() != NULL);
} else {
- histogram = new StatsHistogram(name, minimum, maximum, bucket_count);
- scoped_refptr<Histogram> registered_histogram(NULL);
- StatisticsRecorder::FindHistogram(name, &registered_histogram);
- if (registered_histogram.get() != NULL &&
- registered_histogram.get() != histogram.get())
- histogram = registered_histogram;
+ StatsHistogram* stats_histogram = new StatsHistogram(name, minimum, maximum,
+ bucket_count);
+ stats_histogram->InitializeBucketRange();
+ histogram = stats_histogram;
+ StatisticsRecorder::Register(&histogram);
}
DCHECK(HISTOGRAM == histogram->histogram_type());
@@ -48,6 +47,9 @@ scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet(
Histogram* temp_histogram = histogram.get();
StatsHistogram* temp_stats_histogram =
static_cast<StatsHistogram*>(temp_histogram);
+ // Validate upcast by seeing that we're probably providing the checksum.
+ CHECK_EQ(temp_stats_histogram->StatsHistogram::CalculateRangeChecksum(),
+ temp_stats_histogram->CalculateRangeChecksum());
scoped_refptr<StatsHistogram> return_histogram(temp_stats_histogram);
return return_histogram;
}
@@ -91,5 +93,10 @@ Histogram::Inconsistencies StatsHistogram::FindCorruption(
return NO_INCONSISTENCIES; // This class won't monitor inconsistencies.
}
+uint32 StatsHistogram::CalculateRangeChecksum() const {
+ // We don't calculate checksums, so at least establish a unique constant.
+ const uint32 kStatsHistogramChecksum = 0x0cecce;
+ return kStatsHistogramChecksum;
+}
} // namespace disk_cache
diff --git a/net/disk_cache/stats_histogram.h b/net/disk_cache/stats_histogram.h
index 499784c..249327c 100644
--- a/net/disk_cache/stats_histogram.h
+++ b/net/disk_cache/stats_histogram.h
@@ -45,6 +45,7 @@ class StatsHistogram : public base::Histogram {
virtual size_t bucket_count() const;
virtual void SnapshotSample(SampleSet* sample) const;
virtual Inconsistencies FindCorruption(const SampleSet& snapshot) const;
+ virtual uint32 CalculateRangeChecksum() const;
private:
bool init_;