Skip to content

Commit f406d45

Browse files
committed
Add missing bound checks in VP9 SS parser
1 parent 0bd9553 commit f406d45

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

codecs/vp9_packet.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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])

codecs/vp9_packet_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,30 @@ func TestVP9Packet_Unmarshal(t *testing.T) {
167167
Payload: []byte{},
168168
},
169169
},
170+
"ScalabilityStructure_ShortPacket0": {
171+
b: []byte{0x0A, 0x10},
172+
err: errShortPacket,
173+
},
174+
"ScalabilityStructure_ShortPacket1": {
175+
b: []byte{0x0A, 0x10, 0x0, 0x10, 0x10},
176+
err: errShortPacket,
177+
},
178+
"ScalabilityStructure_ShortPacket2": {
179+
b: []byte{0x0A, 0x08},
180+
err: errShortPacket,
181+
},
182+
"ScalabilityStructure_ShortPacket3": {
183+
b: []byte{0x0A, 0x08, 0x01},
184+
err: errShortPacket,
185+
},
186+
"ScalabilityStructure_ShortPacket4": {
187+
b: []byte{0x0A, 0x08, 0x01, 0x04},
188+
err: errShortPacket,
189+
},
190+
"ScalabilityStructure_ShortPacket5": {
191+
b: []byte{0x0A, 0x08, 0x01, 0x08, 0x01},
192+
err: errShortPacket,
193+
},
170194
}
171195
for name, c := range cases {
172196
c := c

0 commit comments

Comments
 (0)