Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add VP8/VP9 limits #348

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
17 changes: 11 additions & 6 deletions pkg/formats/rtpvp8/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"fmt"
"time"

"github.com/bluenviron/mediacommon/pkg/codecs/vp8"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"

Expand Down Expand Up @@ -35,6 +36,7 @@
type Decoder struct {
timeDecoder *rtptime.Decoder
firstPacketReceived bool
fragmentsSize int
fragments [][]byte
}

Expand Down Expand Up @@ -65,6 +67,7 @@
d.firstPacketReceived = true

if !pkt.Marker {
d.fragmentsSize = len(vpkt.Payload)
d.fragments = append(d.fragments, vpkt.Payload)
return nil, 0, ErrMorePacketsNeeded
}
Expand All @@ -79,18 +82,20 @@
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)
}

Check warning on line 90 in pkg/formats/rtpvp8/decoder.go

View check run for this annotation

Codecov / codecov/patch

pkg/formats/rtpvp8/decoder.go#L88-L90

Added lines #L88 - L90 were not covered by tests

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]
}

Expand Down
17 changes: 11 additions & 6 deletions pkg/formats/rtpvp9/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"fmt"
"time"

"github.com/bluenviron/mediacommon/pkg/codecs/vp9"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"

Expand Down Expand Up @@ -35,6 +36,7 @@
type Decoder struct {
timeDecoder *rtptime.Decoder
firstPacketReceived bool
fragmentsSize int
fragments [][]byte
}

Expand All @@ -60,6 +62,7 @@
d.firstPacketReceived = true

if !vpkt.E {
d.fragmentsSize = len(vpkt.Payload)
d.fragments = append(d.fragments, vpkt.Payload)
return nil, 0, ErrMorePacketsNeeded
}
Expand All @@ -74,18 +77,20 @@
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)
}

Check warning on line 85 in pkg/formats/rtpvp9/decoder.go

View check run for this annotation

Codecov / codecov/patch

pkg/formats/rtpvp9/decoder.go#L83-L85

Added lines #L83 - L85 were not covered by tests

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]
}

Expand Down
Loading