Commit 3823cbf3 authored by Chris Palmer's avatar Chris Palmer Committed by Commit Bot

Fix off-by-1 OOB array access in task tracker.

Bug: 978888
Change-Id: Ib16b2e35c2f88e7f554611b21bda48857127c77c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1678937Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Chris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672696}
parent b320af60
...@@ -66,6 +66,8 @@ enum class TaskPriority : uint8_t { ...@@ -66,6 +66,8 @@ enum class TaskPriority : uint8_t {
HIGHEST = USER_BLOCKING HIGHEST = USER_BLOCKING
}; };
using TaskPriorityType = std::underlying_type<TaskPriority>::type;
// Valid shutdown behaviors supported by the thread pool. // Valid shutdown behaviors supported by the thread pool.
enum class TaskShutdownBehavior : uint8_t { enum class TaskShutdownBehavior : uint8_t {
// Tasks posted with this mode which have not started executing before // Tasks posted with this mode which have not started executing before
......
...@@ -306,9 +306,11 @@ TaskTracker::TaskTracker(StringPiece histogram_label) ...@@ -306,9 +306,11 @@ TaskTracker::TaskTracker(StringPiece histogram_label)
"UserBlockingTaskPriority_MayBlock")}}, "UserBlockingTaskPriority_MayBlock")}},
tracked_ref_factory_(this) { tracked_ref_factory_(this) {
// Confirm that all |task_latency_histograms_| have been initialized above. // Confirm that all |task_latency_histograms_| have been initialized above.
DCHECK(*(&task_latency_histograms_[static_cast<int>(TaskPriority::HIGHEST) + for (TaskPriorityType i = 0; i < kNumTaskPriorities; ++i) {
1][0] - for (TaskPriorityType j = 0; j < kNumBlockingModes; ++j) {
1)); DCHECK(task_latency_histograms_[i][j]);
}
}
} }
TaskTracker::~TaskTracker() = default; TaskTracker::~TaskTracker() = default;
......
...@@ -281,12 +281,16 @@ class BASE_EXPORT TaskTracker { ...@@ -281,12 +281,16 @@ class BASE_EXPORT TaskTracker {
// blocking tasks. Intentionally leaked. // blocking tasks. Intentionally leaked.
// TODO(scheduler-dev): Consider using STATIC_HISTOGRAM_POINTER_GROUP for // TODO(scheduler-dev): Consider using STATIC_HISTOGRAM_POINTER_GROUP for
// these. // these.
static constexpr int kNumTaskPriorities = static constexpr auto kNumTaskPriorities =
static_cast<int>(TaskPriority::HIGHEST) + 1; static_cast<TaskPriorityType>(TaskPriority::HIGHEST) + 1;
HistogramBase* const task_latency_histograms_[kNumTaskPriorities][2]; static constexpr TaskPriorityType kNumBlockingModes = 2;
HistogramBase* const heartbeat_latency_histograms_[kNumTaskPriorities][2]; HistogramBase* const task_latency_histograms_[kNumTaskPriorities]
[kNumBlockingModes];
HistogramBase* const heartbeat_latency_histograms_[kNumTaskPriorities]
[kNumBlockingModes];
HistogramBase* const HistogramBase* const
num_tasks_run_while_queuing_histograms_[kNumTaskPriorities][2]; num_tasks_run_while_queuing_histograms_[kNumTaskPriorities]
[kNumBlockingModes];
// Ensures all state (e.g. dangling cleaned up workers) is coalesced before // Ensures all state (e.g. dangling cleaned up workers) is coalesced before
// destroying the TaskTracker (e.g. in test environments). // destroying the TaskTracker (e.g. in test environments).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment