@@ -345,6 +345,9 @@ func (p *VP9Packet) parseSSData(packet []byte, pos int) (int, error) {
345345 p .NG = 0
346346
347347 if p .Y {
348+ if len (packet ) < pos + int (NS )* 4 {
349+ return pos , errShortPacket
350+ }
348351 p .Width = make ([]uint16 , NS )
349352 p .Height = make ([]uint16 , NS )
350353 for i := 0 ; i < int (NS ); i ++ {
@@ -356,16 +359,25 @@ func (p *VP9Packet) parseSSData(packet []byte, pos int) (int, error) {
356359 }
357360
358361 if p .G {
362+ if len (packet ) <= pos {
363+ return pos , errShortPacket
364+ }
359365 p .NG = packet [pos ]
360366 pos ++
361367 }
362368
363369 for i := 0 ; i < int (p .NG ); i ++ {
370+ if len (packet ) <= pos {
371+ return pos , errShortPacket
372+ }
364373 p .PGTID = append (p .PGTID , packet [pos ]>> 5 )
365374 p .PGU = append (p .PGU , packet [pos ]& 0x10 != 0 )
366375 R := (packet [pos ] >> 2 ) & 0x3
367376 pos ++
368377
378+ if len (packet ) < pos + int (R ) {
379+ return pos , errShortPacket
380+ }
369381 p .PGPDiff = append (p .PGPDiff , []uint8 {})
370382 for j := 0 ; j < int (R ); j ++ {
371383 p .PGPDiff [i ] = append (p .PGPDiff [i ], packet [pos ])
0 commit comments