Skip to content

Commit

Permalink
Fix RTP padding length validation
Browse files Browse the repository at this point in the history
Added validation of RTP padding length in received packets. Also check
for zero padding length when marshaling.
  • Loading branch information
sirzooro committed Jul 7, 2024
1 parent bc5124c commit cdd3390
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ var (
errRFC8285TwoByteHeaderSize = errors.New("header extension payload must be 255bytes or less for RFC 5285 two byte extensions")

errRFC3550HeaderIDRange = errors.New("header extension id must be 0 for non-RFC 5285 extensions")

errInvalidRTPPadding = errors.New("invalid RTP padding")
)
7 changes: 7 additions & 0 deletions packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ func (p *Packet) Unmarshal(buf []byte) error {

end := len(buf)
if p.Header.Padding {
if end <= n {
return errTooSmall

Check warning on line 219 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L219

Added line #L219 was not covered by tests
}
p.PaddingSize = buf[end-1]
end -= int(p.PaddingSize)
}
Expand Down Expand Up @@ -475,6 +478,10 @@ func (p Packet) Marshal() (buf []byte, err error) {

// MarshalTo serializes the packet and writes to the buffer.
func (p *Packet) MarshalTo(buf []byte) (n int, err error) {
if p.Header.Padding && p.PaddingSize == 0 {
return 0, errInvalidRTPPadding

Check warning on line 482 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L482

Added line #L482 was not covered by tests
}

n, err = p.Header.MarshalTo(buf)
if err != nil {
return 0, err
Expand Down

0 comments on commit cdd3390

Please sign in to comment.