Skip to content

Commit

Permalink
h264: fix memory filling up in case of malicious SPS (#153)
Browse files Browse the repository at this point in the history
When CpbCntMinus1 is set to unreasonably high values, the RAM fills up.
  • Loading branch information
aler9 authored Oct 20, 2024
1 parent 058cf2b commit 05af021
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/codecs/h264/sps.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (h *SPS_HRD) unmarshal(buf []byte, pos *int) error {
return err
}

if h.CpbCntMinus1 > 31 {
return fmt.Errorf("invalid cpb_cnt_minus1")
}

h.BitRateScale = uint8(bits.ReadBitsUnsafe(buf, pos, 4))
h.CpbSizeScale = uint8(bits.ReadBitsUnsafe(buf, pos, 4))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("'z00]")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("gd\x00\f\xac;l\xb0KB\x00\x00\x03\x02\x00\x00\x03\x00=\b")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("gd\x00\f\xac;M\xb0KB\x00\x00\x00\x02\x00\x00\x03\x00=\b")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("'z001000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("gd\x00\x1f\xac\xd9@P\x05\xbb\x01l@\x00\x00\x03\x00\x80\x00\x00\x1e\a\x8c\x18\xcb")

0 comments on commit 05af021

Please sign in to comment.