[FFmpeg-devel] [PATCH 01/17] avcodec/jacosubdec: add some memory checks

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


---
 libavcodec/jacosubdec.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c
index b64fac8..ef847e2 100644
--- a/libavcodec/jacosubdec.c
+++ b/libavcodec/jacosubdec.c
@@ -168,6 +168,7 @@ static void jacosub_to_ass(AVCodecContext *avctx, AVBPrint *dst, const char *src
 static int jacosub_decode_frame(AVCodecContext *avctx,
                                 void *data, int *got_sub_ptr, AVPacket *avpkt)
 {
+    int ret;
     AVSubtitle *sub = data;
     const char *ptr = avpkt->data;
 
@@ -176,7 +177,6 @@ static int jacosub_decode_frame(AVCodecContext *avctx,
 
     if (*ptr) {
         AVBPrint buffer;
-        char *dec_sub;
 
         // skip timers
         ptr = jss_skip_whitespace(ptr);
@@ -185,9 +185,13 @@ static int jacosub_decode_frame(AVCodecContext *avctx,
 
         av_bprint_init(&buffer, JSS_MAX_LINESIZE, JSS_MAX_LINESIZE);
         jacosub_to_ass(avctx, &buffer, ptr);
-        av_bprint_finalize(&buffer, &dec_sub);
-        ff_ass_add_rect(sub, dec_sub, avpkt->pts, avpkt->duration, 0);
-        av_free(dec_sub);
+        if (!av_bprint_is_complete(&buffer))
+            ret = AVERROR(ENOMEM);
+        else
+            ret = ff_ass_add_rect(sub, buffer.str, avpkt->pts, avpkt->duration, 0);
+        av_bprint_finalize(&buffer, NULL);
+        if (ret < 0)
+            return ret;
     }
 
 end:
-- 
2.1.0



More information about the ffmpeg-devel mailing list