diff mbox series

[FFmpeg-devel,01/11] avformat/mux: Sanitize packets without data and side-data

Message ID AM7PR03MB66603A7CC5678DABF4E3AE1B8FCF9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Headers show
Series [FFmpeg-devel,01/11] avformat/mux: Sanitize packets without data and side-data
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 3, 2021, 11:10 p.m. UTC
The BSF API treats such packets as signalling EOF and therefore
such a packet might corrupt the BSF state. In such a case,
the guarantee that av_interleaved_write_frame() always frees
the packet is not upheld.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
My first attempt was to disallow such packets, but the movenc test
explicitly used them (see signal_init_ts()), so there seems to be
a use for them.

 libavformat/mux.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 6ba1306f2b..dbcd3835c2 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -784,6 +784,13 @@  static int prepare_input_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
     if (st->internal->is_intra_only)
         pkt->flags |= AV_PKT_FLAG_KEY;
 
+    if (!pkt->data && !pkt->side_data_elems) {
+        /* Such empty packets signal EOS for the BSF API; so sanitize
+         * the packet by allocating data of size 0 (+ padding). */
+        av_buffer_unref(&pkt->buf);
+        return av_packet_make_refcounted(pkt);
+    }
+
     return 0;
 }