[FFmpeg-devel] [PATCH 06/17] avcodec/realtextdec: add some memory checks

Clément Bœsch u at pkh.me
Sat Sep 20 22:27:46 CEST 2014


---
 libavcodec/realtextdec.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavcodec/realtextdec.c b/libavcodec/realtextdec.c
index 4578897..603c3c9 100644
--- a/libavcodec/realtextdec.c
+++ b/libavcodec/realtextdec.c
@@ -59,6 +59,7 @@ static int rt_event_to_ass(AVBPrint *buf, const char *p)
 static int realtext_decode_frame(AVCodecContext *avctx,
                                  void *data, int *got_sub_ptr, AVPacket *avpkt)
 {
+    int ret = 0;
     AVSubtitle *sub = data;
     const char *ptr = avpkt->data;
     AVBPrint buf;
@@ -66,10 +67,16 @@ static int realtext_decode_frame(AVCodecContext *avctx,
     av_bprint_init(&buf, 0, 4096);
     // note: no need to rescale pts & duration since they are in the same
     // timebase as ASS (1/100)
-    if (ptr && avpkt->size > 0 && !rt_event_to_ass(&buf, ptr))
-        ff_ass_add_rect(sub, buf.str, avpkt->pts, avpkt->duration, 0);
-    *got_sub_ptr = sub->num_rects > 0;
+    if (ptr && avpkt->size > 0 && !rt_event_to_ass(&buf, ptr)) {
+        if (!av_bprint_is_complete(&buf))
+            ret = AVERROR(ENOMEM);
+        else
+            ret = ff_ass_add_rect(sub, buf.str, avpkt->pts, avpkt->duration, 0);
+    }
     av_bprint_finalize(&buf, NULL);
+    if (ret < 0)
+        return ret;
+    *got_sub_ptr = sub->num_rects > 0;
     return avpkt->size;
 }
 
-- 
2.1.0



More information about the ffmpeg-devel mailing list