diff --git a/codecs/h265_packet.go b/codecs/h265_packet.go index 707b6a7..591566d 100644 --- a/codecs/h265_packet.go +++ b/codecs/h265_packet.go @@ -860,7 +860,7 @@ type H265Payloader struct { } // Payload fragments a H265 packet across one or more byte arrays. -func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint: gocognit +func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint: gocognit,cyclop,funlen var payloads [][]byte if len(payload) == 0 || mtu == 0 { return payloads @@ -928,6 +928,9 @@ func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint: index++ } } + + // Since the type of mtu is uint16, len(nalu) fits in as well, so it is safe. + // #nosec binary.BigEndian.PutUint16(buf[index:index+2], uint16(len(nalu))) index += 2 index += copy(buf[index:], nalu) diff --git a/codecs/h265_packet_test.go b/codecs/h265_packet_test.go index 49adaff..e756627 100644 --- a/codecs/h265_packet_test.go +++ b/codecs/h265_packet_test.go @@ -873,7 +873,7 @@ func TestH265_Packet_Real(t *testing.T) { } } -func TestH265Payloader_Payload(t *testing.T) { +func TestH265Payloader_Payload(t *testing.T) { // nolint: funlen tt := []struct { Name string Data []byte @@ -1141,6 +1141,8 @@ func TestH265Payloader_Real(t *testing.T) { // curl -LO "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h265/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" // ffmpeg -i Big_Buck_Bunny_1080_10s_1MB.mp4 -c:v copy Big_Buck_Bunny_1080_10s_1MB.h265 // hexdump -v -e '1/1 "0x%02x, "' Big_Buck_Bunny_1080_10s_1MB.h265 > aaa + + // nolint: lll payload := []byte{ 0x00, 0x00, 0x00, 0x01, 0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x95, 0x98, 0x09, 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0xa0, 0x03, 0xc0, 0x80, 0x10, 0xe5, 0x96, 0x56, 0x69, 0x24, 0xca, 0xf0, 0x10, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x01, 0xe0, 0x80,