diff --git a/video/encoder_bitrate_adjuster.cc b/video/encoder_bitrate_adjuster.cc index 10c73343ea2..d65688a432d 100644 --- a/video/encoder_bitrate_adjuster.cc +++ b/video/encoder_bitrate_adjuster.cc @@ -382,6 +382,19 @@ void EncoderBitrateAdjuster::OnEncodedFrame(DataSize size, int stream_index, int temporal_index) { ++frames_since_layout_change_; + // `temporal_index` can originate from the temporal_idx field of an + // EncodedImage which is set from external (Mojo IPC) input via + // BitstreamBufferMetadata; reject out-of-range values to avoid OOB + // indexing into `overshoot_detectors_`. + if (stream_index < 0 || + stream_index >= static_cast(kMaxSpatialLayers) || + temporal_index < 0 || + temporal_index >= static_cast(kMaxTemporalStreams)) { + RTC_LOG(LS_WARNING) << "EncoderBitrateAdjuster::OnEncodedFrame ignoring " + "out-of-range indices si=" + << stream_index << " ti=" << temporal_index; + return; + } // Detectors may not exist, for instance if ScreenshareLayers is used. auto& detector = overshoot_detectors_[stream_index][temporal_index]; if (detector) {