Skip to content

Commit

Permalink
Take local copy of UMP::local_sources to iterate
Browse files Browse the repository at this point in the history
Take a local copy of UserMediaProcessor::local_sources_ when iterating
over it in UserMediaProcessor::DetermineExistingAudioSessionId, as the
list can be effectively concurrently modified during destruction of
MediaStreamTracks triggered by GC during this loop. Without the copy
this leads to a container overflow.

Bug: 1238209
Change-Id: I048387a51a58eacff87d220e6b67d2d09f610c1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3320283
Reviewed-by: Henrik Boström <hbos@chromium.org>
Commit-Queue: Tony Herre <toprice@chromium.org>
Cr-Commit-Position: refs/heads/main@{#950499}
  • Loading branch information
Tony Herre authored and Chromium LUCI CQ committed Dec 10, 2021
1 parent 14bd037 commit fb6232f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ void UserMediaProcessor::SelectAudioSettings(

absl::optional<base::UnguessableToken>
UserMediaProcessor::DetermineExistingAudioSessionId() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(current_request_info_->request()->Audio());

auto settings = current_request_info_->audio_capture_settings();
Expand All @@ -735,7 +736,12 @@ UserMediaProcessor::DetermineExistingAudioSessionId() {
// Create a copy of the MediaStreamSource objects that are
// associated to the same audio device capture based on its device ID.
HeapVector<Member<MediaStreamSource>> matching_sources;
for (const auto& source : local_sources_) {

// Take a defensive copy, as local_sources_ can be modified during
// destructions in GC runs triggered by the push_back allocation in this loop.
// crbug.com/1238209
HeapVector<Member<MediaStreamSource>> local_sources_copy = local_sources_;
for (const auto& source : local_sources_copy) {
MediaStreamSource* source_copy = source;
if (source_copy->GetType() == MediaStreamSource::kTypeAudio &&
source_copy->Id().Utf8() == device_id) {
Expand Down

0 comments on commit fb6232f

Please sign in to comment.