mirror of https://bitbucket.org/ausocean/av.git
Added length check to IndexPid.
This commit is contained in:
parent
c8a0b7df07
commit
c717595adc
|
@ -180,6 +180,7 @@ func FindPat(d []byte) ([]byte, int, error) {
|
|||
var (
|
||||
errInvalidLen = errors.New("MPEG-TS data not of valid length")
|
||||
errCouldNotFind = errors.New("could not find packet with given PID")
|
||||
errNotConsecutive = errors.New("could not find consecutive PIDs")
|
||||
)
|
||||
|
||||
// FindPid will take a clip of MPEG-TS and try to find a packet with given PID - if one
|
||||
|
@ -223,10 +224,12 @@ func LastPid(d []byte, pid uint16) (pkt []byte, i int, err error) {
|
|||
func IndexPid(d []byte, pids ...uint16) (idx int, m map[string]string, err error) {
|
||||
idx = -1
|
||||
for _, pid := range pids {
|
||||
pkt, i, _err := FindPid(d, pid)
|
||||
if len(d) < PacketSize {
|
||||
return idx, m, errInvalidLen
|
||||
}
|
||||
pkt, i, err := FindPid(d, pid)
|
||||
if err != nil {
|
||||
err = errors.Wrap(_err, "could not find PID")
|
||||
return
|
||||
return idx, m, errCouldNotFind
|
||||
}
|
||||
if pid == PmtPid {
|
||||
m, _ = metaFromPMT(pkt)
|
||||
|
@ -234,8 +237,7 @@ func IndexPid(d []byte, pids ...uint16) (idx int, m map[string]string, err error
|
|||
if idx == -1 {
|
||||
idx = i
|
||||
} else if i != 0 {
|
||||
err = errors.New("PIDs not consecutive")
|
||||
return
|
||||
return idx, m, errNotConsecutive
|
||||
}
|
||||
d = d[i+PacketSize:]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue