diff --git a/codec/h265parser/parser.go b/codec/h265parser/parser.go index 0521a09c..5117d64f 100644 --- a/codec/h265parser/parser.go +++ b/codec/h265parser/parser.go @@ -537,8 +537,31 @@ func (self *AVCDecoderConfRecord) Unmarshal(b []byte) (n int, err error) { self.ProfileCompatibility = b[2] self.AVCLevelIndication = b[3] self.LengthSizeMinusOne = b[4] & 0x03 - spscount := int(b[5] & 0x1f) - n += 6 + + n = 23 + + n += 2 + vpscount := int(b[n] & 0x1f) + n++ + for i := 0; i < vpscount; i++ { + if len(b) < n+2 { + err = ErrDecconfInvalid + return + } + vpslen := int(pio.U16BE(b[n:])) + n += 2 + + if len(b) < n+vpslen { + err = ErrDecconfInvalid + return + } + self.VPS = append(self.VPS, b[n:n+vpslen]) + n += vpslen + } + + n += 2 + spscount := int(b[n] & 0x1f) + n++ for i := 0; i < spscount; i++ { if len(b) < n+2 { err = ErrDecconfInvalid @@ -554,15 +577,14 @@ func (self *AVCDecoderConfRecord) Unmarshal(b []byte) (n int, err error) { self.SPS = append(self.SPS, b[n:n+spslen]) n += spslen } - if len(b) < n+1 { err = ErrDecconfInvalid return } - ppscount := int(b[n]) + n += 2 + ppscount := int(b[n] & 0x1f) n++ - for i := 0; i < ppscount; i++ { if len(b) < n+2 { err = ErrDecconfInvalid @@ -570,7 +592,6 @@ func (self *AVCDecoderConfRecord) Unmarshal(b []byte) (n int, err error) { } ppslen := int(pio.U16BE(b[n:])) n += 2 - if len(b) < n+ppslen { err = ErrDecconfInvalid return @@ -579,24 +600,6 @@ func (self *AVCDecoderConfRecord) Unmarshal(b []byte) (n int, err error) { n += ppslen } - vpscount := int(b[n]) - n++ - - for i := 0; i < vpscount; i++ { - if len(b) < n+2 { - err = ErrDecconfInvalid - return - } - vpslen := int(pio.U16BE(b[n:])) - n += 2 - - if len(b) < n+vpslen { - err = ErrDecconfInvalid - return - } - self.VPS = append(self.VPS, b[n:n+vpslen]) - n += vpslen - } return }