diff --git a/go.mod b/go.mod index d8eafe1f..92e97c31 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bluenviron/gortsplib/v3 go 1.18 require ( - github.com/bluenviron/mediacommon v0.7.1-0.20230806181841-a2766dec314f + github.com/bluenviron/mediacommon v0.7.1-0.20230806185229-f060a1e5295b github.com/google/uuid v1.3.0 github.com/pion/rtcp v1.2.10 github.com/pion/rtp v1.8.1 diff --git a/go.sum b/go.sum index 1d2fc8ec..88647460 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= github.com/asticode/go-astits v1.12.0 h1:BiefTgVEyPgEB8nT6J+Sys/uxE4H/a04SW/aedpOpPc= github.com/asticode/go-astits v1.12.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI= -github.com/bluenviron/mediacommon v0.7.1-0.20230806181841-a2766dec314f h1:hVo5b6WSVT0+p43GpYv0e4cLtmpkhJp3kD6Ef83jzUM= -github.com/bluenviron/mediacommon v0.7.1-0.20230806181841-a2766dec314f/go.mod h1:LR4w8cpvzo2ZcmBwXcentvBj7ZlyF9g9xP4dDbt8uJw= +github.com/bluenviron/mediacommon v0.7.1-0.20230806185229-f060a1e5295b h1:53WQf0Kam0/Rj4bnTWhpo6n6cCrRE84tjf9xrwq8mWo= +github.com/bluenviron/mediacommon v0.7.1-0.20230806185229-f060a1e5295b/go.mod h1:LR4w8cpvzo2ZcmBwXcentvBj7ZlyF9g9xP4dDbt8uJw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/pkg/formats/rtpvp8/decoder.go b/pkg/formats/rtpvp8/decoder.go index 584c2fc6..704c43c8 100644 --- a/pkg/formats/rtpvp8/decoder.go +++ b/pkg/formats/rtpvp8/decoder.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/bluenviron/mediacommon/pkg/codecs/vp8" "github.com/pion/rtp" "github.com/pion/rtp/codecs" @@ -35,6 +36,7 @@ func joinFragments(fragments [][]byte, size int) []byte { type Decoder struct { timeDecoder *rtptime.Decoder firstPacketReceived bool + fragmentsSize int fragments [][]byte } @@ -65,6 +67,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) { d.firstPacketReceived = true if !pkt.Marker { + d.fragmentsSize = len(vpkt.Payload) d.fragments = append(d.fragments, vpkt.Payload) return nil, 0, ErrMorePacketsNeeded } @@ -79,18 +82,20 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) { return nil, 0, fmt.Errorf("received a non-starting fragment") } + d.fragmentsSize += len(vpkt.Payload) + + if d.fragmentsSize > vp8.MaxFrameSize { + d.fragments = d.fragments[:0] // discard pending fragments + return nil, 0, fmt.Errorf("frame size (%d) is too big, maximum is %d", d.fragmentsSize, vp8.MaxFrameSize) + } + d.fragments = append(d.fragments, vpkt.Payload) if !pkt.Marker { return nil, 0, ErrMorePacketsNeeded } - n := 0 - for _, frag := range d.fragments { - n += len(frag) - } - - frame = joinFragments(d.fragments, n) + frame = joinFragments(d.fragments, d.fragmentsSize) d.fragments = d.fragments[:0] } diff --git a/pkg/formats/rtpvp9/decoder.go b/pkg/formats/rtpvp9/decoder.go index f1e66f29..51b570db 100644 --- a/pkg/formats/rtpvp9/decoder.go +++ b/pkg/formats/rtpvp9/decoder.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/bluenviron/mediacommon/pkg/codecs/vp9" "github.com/pion/rtp" "github.com/pion/rtp/codecs" @@ -35,6 +36,7 @@ func joinFragments(fragments [][]byte, size int) []byte { type Decoder struct { timeDecoder *rtptime.Decoder firstPacketReceived bool + fragmentsSize int fragments [][]byte } @@ -60,6 +62,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) { d.firstPacketReceived = true if !vpkt.E { + d.fragmentsSize = len(vpkt.Payload) d.fragments = append(d.fragments, vpkt.Payload) return nil, 0, ErrMorePacketsNeeded } @@ -74,18 +77,20 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) { return nil, 0, fmt.Errorf("received a non-starting fragment") } + d.fragmentsSize += len(vpkt.Payload) + + if d.fragmentsSize > vp9.MaxFrameSize { + d.fragments = d.fragments[:0] // discard pending fragments + return nil, 0, fmt.Errorf("frame size (%d) is too big, maximum is %d", d.fragmentsSize, vp9.MaxFrameSize) + } + d.fragments = append(d.fragments, vpkt.Payload) if !vpkt.E { return nil, 0, ErrMorePacketsNeeded } - n := 0 - for _, frag := range d.fragments { - n += len(frag) - } - - frame = joinFragments(d.fragments, n) + frame = joinFragments(d.fragments, d.fragmentsSize) d.fragments = d.fragments[:0] }