From a82d88a7a77fb82f39b7f91ba24a9729777d3feb Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Thu, 19 Feb 2026 23:57:58 +0530 Subject: [PATCH] Protect against incorrect temporal layer. (#4327) Seeing some tracks with temporal layer higher than array bounds. Protect against it and log some info to understand better. --- pkg/sfu/streamtracker/streamtracker.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/sfu/streamtracker/streamtracker.go b/pkg/sfu/streamtracker/streamtracker.go index 34a4a97de..0a2229e85 100644 --- a/pkg/sfu/streamtracker/streamtracker.go +++ b/pkg/sfu/streamtracker/streamtracker.go @@ -69,8 +69,8 @@ type StreamTracker struct { lastNotifiedStatus StreamStatus lastBitrateReport time.Time - bytesForBitrate [4]int64 - bitrate [4]int64 + bytesForBitrate [buffer.DefaultMaxLayerTemporal + 1]int64 + bitrate [buffer.DefaultMaxLayerTemporal + 1]int64 isStopped bool } @@ -207,8 +207,17 @@ func (s *StreamTracker) Observe( go s.worker(s.generation.Load()) } - if temporalLayer >= 0 { + if temporalLayer >= 0 && int(temporalLayer) < len(s.bytesForBitrate) { s.bytesForBitrate[temporalLayer] += int64(pktSize) + } else if int(temporalLayer) >= len(s.bytesForBitrate) { + s.params.Logger.Warnw( + "invalid temporal layer", nil, + "temporalLayer", temporalLayer, + "pktSize", pktSize, + "payloadSize", payloadSize, + "hasMarker", hasMarker, + "ts", ts, + ) } s.lock.Unlock()