From 370bddff29eb1b83f7bd76026566c91a3e27ec2b Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 14:56:40 -0500 Subject: [PATCH 01/16] sout: rtp: bail if xiph config packet failed This can happen on running out of memory, failed parsing or a NULL fmtp. --- modules/stream_out/rtp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c index e59ab95155f0..5f024499caee 100644 --- a/modules/stream_out/rtp.c +++ b/modules/stream_out/rtp.c @@ -1223,8 +1223,10 @@ static int Send( sout_stream_t *p_stream, void *_id, block_t *p_buffer ) id->b_first_packet = false; if (!strcmp(id->rtp_fmt.ptname, "vorbis") || !strcmp(id->rtp_fmt.ptname, "theora")) - rtp_packetize_xiph_config(id, id->rtp_fmt.fmtp, - p_buffer->i_pts); + { + if (rtp_packetize_xiph_config(id, id->rtp_fmt.fmtp, p_buffer->i_pts)) + break; + } } if( id->rtp_fmt.pf_packetize( id, p_buffer ) ) -- GitLab From 3e0a234bbff564dd64c982a05f02d4b469579156 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:20:11 -0500 Subject: [PATCH 02/16] sout: rtp: use VLC_ENOMEM when appropriate --- modules/stream_out/rtpfmt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index f4e675665f0c..24d20f148772 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -725,8 +725,8 @@ int rtp_packetize_xiph_config( sout_stream_id_sys_t *id, const char *fmtp, size_t len = end - start; char *b64 = malloc(len + 1); - if(!b64) - return VLC_EGENERIC; + if (unlikely(b64 == NULL)) + return VLC_ENOMEM; memcpy(b64, start, len); b64[len] = '\0'; -- GitLab From c652c01e46a8812a26d56309d30f737717101a05 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:22:30 -0500 Subject: [PATCH 03/16] sout: rtp: xiph_config: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 24d20f148772..595f935c873e 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -752,6 +752,11 @@ int rtp_packetize_xiph_config( sout_stream_id_sys_t *id, const char *fmtp, { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 18 + i_payload ); + if (unlikely(out == NULL)) + { + free(p_orig); + return VLC_ENOMEM; + } unsigned fragtype, numpkts; if (i_count == 1) -- GitLab From bb714dbca7296115cdf256a64c9ba6c0fb35bde6 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:24:54 -0500 Subject: [PATCH 04/16] sout: rtp: xiph: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 595f935c873e..eefcf66ec401 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -811,6 +811,11 @@ static int rtp_packetize_xiph( sout_stream_id_sys_t *id, block_t *in ) { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 18 + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } unsigned fragtype, numpkts; if (i_count == 1) -- GitLab From 54d1659e2423190bb9118e65b241c2211340eaaf Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:27:27 -0500 Subject: [PATCH 05/16] sout: rtp: mpa: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index eefcf66ec401..1207ed9a5b3d 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -872,6 +872,11 @@ static int rtp_packetize_mpa( sout_stream_id_sys_t *id, block_t *in ) { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 16 + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } /* rtp common header */ rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts ); -- GitLab From 95a8c51804ab282149158e1dcce5a5d91156aa42 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:27:55 -0500 Subject: [PATCH 06/16] sout: rtp: mpv: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 1207ed9a5b3d..e8a5f8be2018 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -955,6 +955,12 @@ static int rtp_packetize_mpv( sout_stream_id_sys_t *id, block_t *in ) { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 16 + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } + /* MBZ:5 T:1 TR:10 AN:1 N:1 S:1 B:1 E:1 P:3 FBV:1 BFC:3 FFV:1 FFC:3 */ uint32_t h = ( i_temporal_ref << 16 )| ( b_sequence_start << 13 )| -- GitLab From f74404f331efa5fef4cf0eaf19448ff4ff97d557 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:28:51 -0500 Subject: [PATCH 07/16] sout: rtp: ac3: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index e8a5f8be2018..4ad3e6f3a10d 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1013,6 +1013,11 @@ static int rtp_packetize_ac3( sout_stream_id_sys_t *id, block_t *in ) { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 14 + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } /* rtp common header */ rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts ); -- GitLab From eb3ee28d107d67a7857da69db0b41cfcd948350e Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:29:58 -0500 Subject: [PATCH 08/16] sout: rtp: eac3: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 4ad3e6f3a10d..3ab8c96f9d7f 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1049,6 +1049,11 @@ static int rtp_packetize_eac3(sout_stream_id_sys_t *id, block_t *in) bool last = i == (frag_count - 1); size_t len = last ? in->i_buffer : mtu; block_t *out = block_Alloc(14 + len); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } rtp_packetize_common(id, out, false, in->i_pts); out->p_buffer[12] = frame_type; -- GitLab From 6f15847a53def95fb8269bbe0626976f2fb34eed Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:31:48 -0500 Subject: [PATCH 09/16] sout: rtp: split: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 3ab8c96f9d7f..f5d739d153ba 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1096,6 +1096,11 @@ static int rtp_packetize_split( sout_stream_id_sys_t *id, block_t *in ) { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 12 + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } /* rtp common header */ rtp_packetize_common( id, out, (i == i_count - 1), -- GitLab From 931cb15eaddcb90f07973a5ce95397f7d7ad5b65 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:50:26 -0500 Subject: [PATCH 10/16] sout: rtp: mp4_latm: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index f5d739d153ba..c3a268000503 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1202,6 +1202,11 @@ static int rtp_packetize_mp4a_latm( sout_stream_id_sys_t *id, block_t *in ) if( i != 0 ) latmhdrsize = 0; out = block_Alloc( 12 + latmhdrsize + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } /* rtp common header */ rtp_packetize_common( id, out, ((i == i_count - 1) ? 1 : 0), -- GitLab From f34248bdd560a4bbf7030cd89d9dc6e182785dba Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:51:30 -0500 Subject: [PATCH 11/16] sout: rtp: h263: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index c3a268000503..a3478309e310 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1316,6 +1316,11 @@ static int rtp_packetize_h263( sout_stream_id_sys_t *id, block_t *in ) { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( RTP_H263_PAYLOAD_START + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } b_p_bit = (i == 0) ? 1 : 0; h = ( b_p_bit << 10 )| ( b_v_bit << 9 )| -- GitLab From c70197a440e4ac4214d5b77e4f83ab54e0ee3d14 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:54:14 -0500 Subject: [PATCH 12/16] sout: rtp: h264: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index a3478309e310..9a70e14dc49d 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1370,6 +1370,10 @@ rtp_packetize_h264_nal( sout_stream_id_sys_t *id, { /* Single NAL unit packet */ block_t *out = block_Alloc( 12 + i_data ); + if (unlikely(out == NULL)) + { + return VLC_ENOMEM; + } out->i_dts = i_dts; out->i_length = i_length; @@ -1393,6 +1397,10 @@ rtp_packetize_h264_nal( sout_stream_id_sys_t *id, { const int i_payload = __MIN( i_data, i_max-2 ); block_t *out = block_Alloc( 12 + 2 + i_payload ); + if (unlikely(out == NULL)) + { + return VLC_ENOMEM; + } out->i_dts = i_dts + i * i_length / i_count; out->i_length = i_length / i_count; @@ -1424,9 +1432,13 @@ static int rtp_packetize_h264( sout_stream_id_sys_t *id, block_t *in ) while( hxxx_annexb_iterate_next( &it, &p_nal, &i_nal ) ) { /* TODO add STAP-A to remove a lot of overhead with small slice/sei/... */ - rtp_packetize_h264_nal( id, p_nal, i_nal, + if (rtp_packetize_h264_nal( id, p_nal, i_nal, (in->i_pts != VLC_TICK_INVALID ? in->i_pts : in->i_dts), in->i_dts, - it.p_head + 3 >= it.p_tail, in->i_length * i_nal / in->i_buffer ); + it.p_head + 3 >= it.p_tail, in->i_length * i_nal / in->i_buffer )) + { + block_Release(in); + return VLC_ENOMEM; + } } block_Release(in); -- GitLab From a93de21b653052efc605731909af8b8c2ecd6183 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:56:19 -0500 Subject: [PATCH 13/16] sout: rtp: h265: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 9a70e14dc49d..12def8b99b97 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1461,6 +1461,10 @@ rtp_packetize_h265_nal( sout_stream_id_sys_t *id, { /* Single NAL unit packet */ block_t *out = block_Alloc( 12 + i_data ); + if (unlikely(out == NULL)) + { + return VLC_ENOMEM; + } out->i_dts = i_dts; out->i_length = i_length; @@ -1486,6 +1490,10 @@ rtp_packetize_h265_nal( sout_stream_id_sys_t *id, { const size_t i_payload = __MIN( i_data, i_max-3 ); block_t *out = block_Alloc( 12 + 3 + i_payload ); + if (unlikely(out == NULL)) + { + return VLC_ENOMEM; + } out->i_dts = i_dts + i * i_length / i_count; out->i_length = i_length / i_count; @@ -1517,9 +1525,13 @@ static int rtp_packetize_h265( sout_stream_id_sys_t *id, block_t *in ) size_t i_nal; while( hxxx_annexb_iterate_next( &it, &p_nal, &i_nal ) ) { - rtp_packetize_h265_nal( id, p_nal, i_nal, + if (rtp_packetize_h265_nal( id, p_nal, i_nal, (in->i_pts != VLC_TICK_INVALID ? in->i_pts : in->i_dts), in->i_dts, - it.p_head + 3 >= it.p_tail, in->i_length * i_nal / in->i_buffer ); + it.p_head + 3 >= it.p_tail, in->i_length * i_nal / in->i_buffer )) + { + block_Release(in); + return VLC_ENOMEM; + } } block_Release(in); -- GitLab From 7309e0fd8551a8d3d824f77f526829b7a7af4a65 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:57:10 -0500 Subject: [PATCH 14/16] sout: rtp: amr: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 12def8b99b97..4b133880e602 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1552,6 +1552,11 @@ static int rtp_packetize_amr( sout_stream_id_sys_t *id, block_t *in ) { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 14 + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } /* rtp common header */ rtp_packetize_common( id, out, ((i == i_count - 1)?1:0), -- GitLab From 1da2229527d66d59a1f3da4df736f0c5bbb57239 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:58:25 -0500 Subject: [PATCH 15/16] sout: rtp: spx: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 4b133880e602..b41875c5859b 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1667,6 +1667,11 @@ static int rtp_packetize_spx( sout_stream_id_sys_t *id, block_t *in ) Allow for 12 extra bytes of RTP header. */ p_out = block_Alloc( 12 + i_payload_size ); + if (unlikely(p_out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } if ( i_payload_padding ) { -- GitLab From 2a2d3b40876fe9a7e2db1245b4ae910d0cb1f502 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tmatth@videolan.org> Date: Fri, 13 Dec 2024 15:58:51 -0500 Subject: [PATCH 16/16] sout: rtp: g726: bail if block_Alloc failed --- modules/stream_out/rtpfmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index b41875c5859b..c78d94c9f2d7 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -1728,6 +1728,11 @@ static int rtp_packetize_g726( sout_stream_id_sys_t *id, block_t *in, int i_pad { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 12 + i_payload ); + if (unlikely(out == NULL)) + { + block_Release(in); + return VLC_ENOMEM; + } /* rtp common header */ rtp_packetize_common( id, out, 0, -- GitLab