mirror of https://bitbucket.org/ausocean/av.git
mts: FindPmt checks validity of data length
This commit is contained in:
parent
0b9f0f49fe
commit
24f0be9917
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue