Skip to content

Commit 14c61dc

Browse files
Uladzimir FilipchenkauSean-Der
Uladzimir Filipchenkau
authored andcommittedMar 29, 2024·
Fix out of range access in VP8 Unmarshal
When unmarshaling 0x81, 0x81, 0x94 panic: runtime error: index out of range [3] with length 3
1 parent a18e24d commit 14c61dc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

Diff for: ‎codecs/vp8_packet.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type VP8Packet struct {
123123
}
124124

125125
// Unmarshal parses the passed byte slice and stores the result in the VP8Packet this method is called upon
126-
func (p *VP8Packet) Unmarshal(payload []byte) ([]byte, error) {
126+
func (p *VP8Packet) Unmarshal(payload []byte) ([]byte, error) { //nolint: gocognit
127127
if payload == nil {
128128
return nil, errNilPacket
129129
}
@@ -163,6 +163,9 @@ func (p *VP8Packet) Unmarshal(payload []byte) ([]byte, error) {
163163
return nil, errShortPacket
164164
}
165165
if payload[payloadIndex]&0x80 > 0 { // M == 1, PID is 16bit
166+
if payloadIndex+1 >= payloadLen {
167+
return nil, errShortPacket
168+
}
166169
p.PictureID = (uint16(payload[payloadIndex]&0x7F) << 8) | uint16(payload[payloadIndex+1])
167170
payloadIndex += 2
168171
} else {

Diff for: ‎codecs/vp8_packet_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestVP8Packet_Unmarshal(t *testing.T) {
106106
// attention to partition boundaries. In that case, it may
107107
// produce packets with minimal headers.
108108

109-
// The next two have been witnessed in nature.
109+
// The next three have been witnessed in nature.
110110
_, err = pck.Unmarshal([]byte{0x00})
111111
if err != nil {
112112
t.Errorf("Empty packet with trivial header: %v", err)
@@ -115,6 +115,13 @@ func TestVP8Packet_Unmarshal(t *testing.T) {
115115
if err != nil {
116116
t.Errorf("Non-empty packet with trivial header: %v", err)
117117
}
118+
raw, err = pck.Unmarshal([]byte{0x81, 0x81, 0x94})
119+
if raw != nil {
120+
t.Fatal("Result should be nil in case of error")
121+
}
122+
if !errors.Is(err, errShortPacket) {
123+
t.Fatal("Error should be:", errShortPacket)
124+
}
118125

119126
// The following two were invented.
120127
_, err = pck.Unmarshal([]byte{0x80, 0x00})

0 commit comments

Comments
 (0)
Please sign in to comment.