mts: FindPmt checks validity of data length

This commit is contained in:
saxon 2018-12-14 16:15:02 +10:30
parent 0b9f0f49fe
commit 24f0be9917
1 changed files with 3 additions and 0 deletions

View File

@ -130,6 +130,9 @@ type Packet struct {
// FindPMT will take a clip of mpegts and try to find a PMT table - if one // FindPMT will take a clip of mpegts and try to find a PMT table - if one
// is found, then it is returned, otherwise nil and an error is returned. // is found, then it is returned, otherwise nil and an error is returned.
func FindPMT(d []byte) (p []byte, err error) { func FindPMT(d []byte) (p []byte, err error) {
if len(d) < mpegTsSize {
return nil, errors.New("Mmpegts data not of valid length")
}
for i := 0; i < len(d); i += mpegTsSize { for i := 0; i < len(d); i += mpegTsSize {
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2]) pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
if pid == pmtPid { if pid == pmtPid {