From d7784b24c6199ced0994faf46647f703a6aa2e76 Mon Sep 17 00:00:00 2001 From: Alex X Date: Sat, 4 Nov 2023 09:42:50 +0300 Subject: [PATCH] Fix memory overflow on bad RTSP sources #675 --- pkg/h264/rtp.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/h264/rtp.go b/pkg/h264/rtp.go index c928f54b..b4a9dafb 100644 --- a/pkg/h264/rtp.go +++ b/pkg/h264/rtp.go @@ -29,6 +29,12 @@ func RTPDepay(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc { return } + // Memory overflow protection. Can happen if we miss a lot of packets with the marker. + // https://github.com/AlexxIT/go2rtc/issues/675 + if len(buf) > 5*1024*1024 { + buf = buf[: 0 : 512*1024] + } + // Fix TP-Link Tapo TC70: sends SPS and PPS with packet.Marker = true // Reolink Duo 2: sends SPS with Marker and PPS without if packet.Marker && len(payload) < PSMaxSize {