Skip to content

Commit

Permalink
h264: apply NALU count limit during Annex-B and AVCC unmarshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Oct 9, 2022
1 parent 74f941b commit e97d290
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/h264/annexb.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ outer:
}
}

if (n + 1) > MaxNALUsPerGroup {
return nil, fmt.Errorf("number of NALUs contained inside a single group (%d) is too big (maximum is %d)",
n+1, MaxNALUsPerGroup)
}

ret := make([][]byte, n+1)
pos := 0
start = initZeroCount + 1
Expand Down
5 changes: 5 additions & 0 deletions pkg/h264/avcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func AVCCUnmarshal(buf []byte) ([][]byte, error) {
return nil, fmt.Errorf("NALU size (%d) is too big (maximum is %d)", bl-pos, MaxNALUSize)
}

if (len(ret) + 1) > MaxNALUsPerGroup {
return nil, fmt.Errorf("number of NALUs contained inside a single group (%d) is too big (maximum is %d)",
len(ret)+1, MaxNALUsPerGroup)
}

ret = append(ret, buf[pos:pos+le])
pos += le

Expand Down
2 changes: 1 addition & 1 deletion pkg/rtph264/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (d *Decoder) DecodeUntilMarker(pkt *rtp.Packet) ([][]byte, time.Duration, e
return nil, 0, err
}

if (len(d.naluBuffer) + len(nalus)) >= h264.MaxNALUsPerGroup {
if (len(d.naluBuffer) + len(nalus)) > h264.MaxNALUsPerGroup {
return nil, 0, fmt.Errorf("number of NALUs contained inside a single group (%d) is too big (maximum is %d)",
len(d.naluBuffer)+len(nalus), h264.MaxNALUsPerGroup)
}
Expand Down

0 comments on commit e97d290

Please sign in to comment.