rtpmpeg2audio: discard fragments in case of errors (#260)

This commit is contained in:
Alessandro Ros
2023-04-26 12:27:24 +02:00
committed by GitHub
parent 4d594cfe6b
commit d6a55f882a

View File

@@ -31,11 +31,13 @@ func (d *Decoder) Init() {
// Decode decodes frames from a RTP/MPEG2-audio packet.
func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
if len(pkt.Payload) < 5 {
d.fragments = d.fragments[:0] // discard pending fragmented packets
return nil, 0, fmt.Errorf("payload is too short")
}
mbz := uint16(pkt.Payload[0])<<8 | uint16(pkt.Payload[1])
if mbz != 0 {
d.fragments = d.fragments[:0] // discard pending fragmented packets
return nil, 0, fmt.Errorf("invalid MBZ: %v", mbz)
}