diff mbox series

[FFmpeg-devel,07/10] avformat/nutenc: Check allocations implicit in dynamic buffers

Message ID 20200504182250.26141-7-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,01/10] libavformat/nutenc: Remove redundant function parameter
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt May 4, 2020, 6:22 p.m. UTC
For nut_write_trailer() this includes actually returning such errors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/nutenc.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

Comments

Michael Niedermayer May 5, 2020, 1:34 p.m. UTC | #1
On Mon, May 04, 2020 at 08:22:47PM +0200, Andreas Rheinhardt wrote:
> For nut_write_trailer() this includes actually returning such errors.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/nutenc.c | 33 ++++++++++++++++++++++++---------
>  1 file changed, 24 insertions(+), 9 deletions(-)

should be ok

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 404a265597..ab44214efd 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -331,13 +331,16 @@  static void put_str(AVIOContext *bc, const char *string)
     avio_write(bc, string, len);
 }
 
-static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
+static int put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
                        const uint8_t *prelude, int prelude_size, uint64_t startcode)
 {
     uint8_t *dyn_buf = NULL;
     int dyn_size     = dyn_bc ? avio_get_dyn_buf(dyn_bc, &dyn_buf) : 0;
     unsigned forw_ptr = prelude_size + dyn_size + 4;
 
+    if (dyn_bc && dyn_bc->error < 0)
+        return dyn_bc->error;
+
     if (forw_ptr > 4096)
         ffio_init_checksum(bc, ff_crc04C11DB7_update, 0);
     avio_wb64(bc, startcode);
@@ -354,6 +357,7 @@  static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
     }
     avio_wl32(bc, ffio_get_checksum(bc));
 
+    return 0;
 }
 
 static void write_mainheader(NUTContext *nut, AVIOContext *bc)
@@ -644,28 +648,39 @@  static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
     if (ret < 0)
         return ret;
     write_mainheader(nut, dyn_bc);
-    put_packet(nut, bc, dyn_bc, NULL, 0, MAIN_STARTCODE);
+    ret = put_packet(nut, bc, dyn_bc, NULL, 0, MAIN_STARTCODE);
+    if (ret < 0)
+        goto fail;
 
     for (i = 0; i < nut->avf->nb_streams; i++) {
         ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i);
         if (ret < 0) {
             goto fail;
         }
-        put_packet(nut, bc, dyn_bc, NULL, 0, STREAM_STARTCODE);
+        ret = put_packet(nut, bc, dyn_bc, NULL, 0, STREAM_STARTCODE);
+        if (ret < 0)
+            goto fail;
     }
 
     write_globalinfo(nut, dyn_bc, prelude, &prelude_size);
-    put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+    ret = put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+    if (ret < 0)
+        goto fail;
 
     for (i = 0; i < nut->avf->nb_streams; i++) {
         ret = write_streaminfo(nut, dyn_bc, i, prelude, &prelude_size);
-        if (ret > 0)
-            put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+        if (!ret)
+            continue;
+        ret = put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+        if (ret < 0)
+            goto fail;
     }
 
     for (i = 0; i < nut->avf->nb_chapters; i++) {
         write_chapter(nut, dyn_bc, i, prelude, &prelude_size);
-        put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+        ret = put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+        if (ret < 0)
+            goto fail;
     }
 
     nut->last_syncpoint_pos = INT_MIN;
@@ -1170,11 +1185,11 @@  static int nut_write_trailer(AVFormatContext *s)
     if (ret >= 0) {
         av_assert1(nut->write_index); // sp_count should be 0 if no index is going to be written
         write_index(nut, dyn_bc);
-        put_packet(nut, bc, dyn_bc, NULL, 0, INDEX_STARTCODE);
+        ret = put_packet(nut, bc, dyn_bc, NULL, 0, INDEX_STARTCODE);
         ffio_free_dyn_buf(&dyn_bc);
     }
 
-    return 0;
+    return ret;
 }
 
 static void nut_write_deinit(AVFormatContext *s)