[FFmpeg-cvslog] Merge commit '212c6a1d70df011b6f2a2aa02f7677503287bd00'

Clément Bœsch git at videolan.org
Fri Apr 7 11:52:34 EEST 2017


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Fri Apr  7 10:17:53 2017 +0200| [9c7ee37490d21350ab1a2e07069284daf1943e52] | committer: Clément Bœsch

Merge commit '212c6a1d70df011b6f2a2aa02f7677503287bd00'

* commit '212c6a1d70df011b6f2a2aa02f7677503287bd00':
  mjpegdec: Check return values of functions that may fail

Merged-by: Clément Bœsch <u at pkh.me>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9c7ee37490d21350ab1a2e07069284daf1943e52
---

 libavcodec/mjpegdec.c | 70 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 48 insertions(+), 22 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 5470b66..cef3b38 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -71,20 +71,36 @@ static int build_vlc(VLC *vlc, const uint8_t *bits_table,
                               huff_code, 2, 2, huff_sym, 2, 2, use_static);
 }
 
-static void build_basic_mjpeg_vlc(MJpegDecodeContext *s)
+static int build_basic_mjpeg_vlc(MJpegDecodeContext *s)
 {
-    build_vlc(&s->vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
-              avpriv_mjpeg_val_dc, 12, 0, 0);
-    build_vlc(&s->vlcs[0][1], avpriv_mjpeg_bits_dc_chrominance,
-              avpriv_mjpeg_val_dc, 12, 0, 0);
-    build_vlc(&s->vlcs[1][0], avpriv_mjpeg_bits_ac_luminance,
-              avpriv_mjpeg_val_ac_luminance, 251, 0, 1);
-    build_vlc(&s->vlcs[1][1], avpriv_mjpeg_bits_ac_chrominance,
-              avpriv_mjpeg_val_ac_chrominance, 251, 0, 1);
-    build_vlc(&s->vlcs[2][0], avpriv_mjpeg_bits_ac_luminance,
-              avpriv_mjpeg_val_ac_luminance, 251, 0, 0);
-    build_vlc(&s->vlcs[2][1], avpriv_mjpeg_bits_ac_chrominance,
-              avpriv_mjpeg_val_ac_chrominance, 251, 0, 0);
+    int ret;
+
+    if ((ret = build_vlc(&s->vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
+                         avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
+        return ret;
+
+    if ((ret = build_vlc(&s->vlcs[0][1], avpriv_mjpeg_bits_dc_chrominance,
+                         avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
+        return ret;
+
+    if ((ret = build_vlc(&s->vlcs[1][0], avpriv_mjpeg_bits_ac_luminance,
+                         avpriv_mjpeg_val_ac_luminance, 251, 0, 1)) < 0)
+        return ret;
+
+    if ((ret = build_vlc(&s->vlcs[1][1], avpriv_mjpeg_bits_ac_chrominance,
+                         avpriv_mjpeg_val_ac_chrominance, 251, 0, 1)) < 0)
+        return ret;
+
+    if ((ret = build_vlc(&s->vlcs[2][0], avpriv_mjpeg_bits_ac_luminance,
+                         avpriv_mjpeg_val_ac_luminance, 251, 0, 0)) < 0)
+        return ret;
+
+    if ((ret = build_vlc(&s->vlcs[2][1], avpriv_mjpeg_bits_ac_chrominance,
+                         avpriv_mjpeg_val_ac_chrominance, 251, 0, 0)) < 0)
+        return ret;
+
+
+    return 0;
 }
 
 static void parse_avid(MJpegDecodeContext *s, uint8_t *buf, int len)
@@ -110,6 +126,7 @@ static void init_idct(AVCodecContext *avctx)
 av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
 {
     MJpegDecodeContext *s = avctx->priv_data;
+    int ret;
 
     if (!s->picture_ptr) {
         s->picture = av_frame_alloc();
@@ -131,11 +148,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
     avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
     avctx->colorspace = AVCOL_SPC_BT470BG;
 
-    build_basic_mjpeg_vlc(s);
+    if ((ret = build_basic_mjpeg_vlc(s)) < 0)
+        return ret;
 
     if (s->extern_huff) {
         av_log(avctx, AV_LOG_INFO, "using external huffman table\n");
-        init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8);
+        if ((ret = init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8)) < 0)
+            return ret;
         if (ff_mjpeg_decode_dht(s)) {
             av_log(avctx, AV_LOG_ERROR,
                    "error using external huffman table, switching back to internal\n");
@@ -307,7 +326,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
         height= s->height;
 
     av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height);
-    if (av_image_check_size(width, height, 0, s->avctx))
+    if (av_image_check_size(width, height, 0, s->avctx) < 0)
         return AVERROR_INVALIDDATA;
 
     nb_components = get_bits(&s->gb, 8);
@@ -969,6 +988,9 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int p
 
     av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
                    (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));
+    if (!s->ljpeg_buffer)
+        return AVERROR(ENOMEM);
+
     buffer = s->ljpeg_buffer;
 
     for (i = 0; i < 4; i++)
@@ -2116,19 +2138,22 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
 
         /* process markers */
-        if (start_code >= 0xd0 && start_code <= 0xd7)
+        if (start_code >= 0xd0 && start_code <= 0xd7) {
             av_log(avctx, AV_LOG_DEBUG,
                    "restart marker: %d\n", start_code & 0x0f);
             /* APP fields */
-        else if (start_code >= APP0 && start_code <= APP15)
-            mjpeg_decode_app(s);
+        } else if (start_code >= APP0 && start_code <= APP15) {
+            if ((ret = mjpeg_decode_app(s)) < 0)
+                return ret;
             /* Comment */
-        else if (start_code == COM) {
+        } else if (start_code == COM) {
             ret = mjpeg_decode_com(s);
             if (ret < 0)
                 return ret;
         } else if (start_code == DQT) {
-            ff_mjpeg_decode_dqt(s);
+            ret = ff_mjpeg_decode_dqt(s);
+            if (ret < 0)
+                return ret;
         }
 
         ret = -1;
@@ -2256,7 +2281,8 @@ eoi_parser:
                 goto fail;
             break;
         case DRI:
-            mjpeg_decode_dri(s);
+            if ((ret = mjpeg_decode_dri(s)) < 0)
+                return ret;
             break;
         case SOF5:
         case SOF6:


======================================================================

diff --cc libavcodec/mjpegdec.c
index 5470b66,f6e9038..cef3b38
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@@ -71,42 -68,38 +71,58 @@@ static int build_vlc(VLC *vlc, const ui
                                huff_code, 2, 2, huff_sym, 2, 2, use_static);
  }
  
- static void build_basic_mjpeg_vlc(MJpegDecodeContext *s)
+ static int build_basic_mjpeg_vlc(MJpegDecodeContext *s)
  {
-     build_vlc(&s->vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
-               avpriv_mjpeg_val_dc, 12, 0, 0);
-     build_vlc(&s->vlcs[0][1], avpriv_mjpeg_bits_dc_chrominance,
-               avpriv_mjpeg_val_dc, 12, 0, 0);
-     build_vlc(&s->vlcs[1][0], avpriv_mjpeg_bits_ac_luminance,
-               avpriv_mjpeg_val_ac_luminance, 251, 0, 1);
-     build_vlc(&s->vlcs[1][1], avpriv_mjpeg_bits_ac_chrominance,
-               avpriv_mjpeg_val_ac_chrominance, 251, 0, 1);
-     build_vlc(&s->vlcs[2][0], avpriv_mjpeg_bits_ac_luminance,
-               avpriv_mjpeg_val_ac_luminance, 251, 0, 0);
-     build_vlc(&s->vlcs[2][1], avpriv_mjpeg_bits_ac_chrominance,
-               avpriv_mjpeg_val_ac_chrominance, 251, 0, 0);
+     int ret;
+ 
+     if ((ret = build_vlc(&s->vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
+                          avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
+         return ret;
+ 
+     if ((ret = build_vlc(&s->vlcs[0][1], avpriv_mjpeg_bits_dc_chrominance,
+                          avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
+         return ret;
+ 
+     if ((ret = build_vlc(&s->vlcs[1][0], avpriv_mjpeg_bits_ac_luminance,
+                          avpriv_mjpeg_val_ac_luminance, 251, 0, 1)) < 0)
+         return ret;
+ 
+     if ((ret = build_vlc(&s->vlcs[1][1], avpriv_mjpeg_bits_ac_chrominance,
+                          avpriv_mjpeg_val_ac_chrominance, 251, 0, 1)) < 0)
+         return ret;
+ 
+     if ((ret = build_vlc(&s->vlcs[2][0], avpriv_mjpeg_bits_ac_luminance,
+                          avpriv_mjpeg_val_ac_luminance, 251, 0, 0)) < 0)
+         return ret;
+ 
+     if ((ret = build_vlc(&s->vlcs[2][1], avpriv_mjpeg_bits_ac_chrominance,
+                          avpriv_mjpeg_val_ac_chrominance, 251, 0, 0)) < 0)
+         return ret;
+ 
+ 
+     return 0;
  }
  
 +static void parse_avid(MJpegDecodeContext *s, uint8_t *buf, int len)
 +{
 +    s->buggy_avid = 1;
 +    if (len > 14 && buf[12] == 1) /* 1 - NTSC */
 +        s->interlace_polarity = 1;
 +    if (len > 14 && buf[12] == 2) /* 2 - PAL */
 +        s->interlace_polarity = 0;
 +    if (s->avctx->debug & FF_DEBUG_PICT_INFO)
 +        av_log(s->avctx, AV_LOG_INFO, "AVID: len:%d %d\n", len, len > 14 ? buf[12] : -1);
 +}
 +
 +static void init_idct(AVCodecContext *avctx)
 +{
 +    MJpegDecodeContext *s = avctx->priv_data;
 +
 +    ff_idctdsp_init(&s->idsp, avctx);
 +    ff_init_scantable(s->idsp.idct_permutation, &s->scantable,
 +                      ff_zigzag_direct);
 +}
 +
  av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
  {
      MJpegDecodeContext *s = avctx->priv_data;
@@@ -131,15 -126,17 +148,17 @@@
      avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
      avctx->colorspace = AVCOL_SPC_BT470BG;
  
-     build_basic_mjpeg_vlc(s);
+     if ((ret = build_basic_mjpeg_vlc(s)) < 0)
+         return ret;
  
      if (s->extern_huff) {
 -        av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
 +        av_log(avctx, AV_LOG_INFO, "using external huffman table\n");
-         init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8);
+         if ((ret = init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8)) < 0)
+             return ret;
 -        if ((ret = ff_mjpeg_decode_dht(s))) {
 +        if (ff_mjpeg_decode_dht(s)) {
              av_log(avctx, AV_LOG_ERROR,
 -                   "mjpeg: error using external huffman table\n");
 -            return ret;
 +                   "error using external huffman table, switching back to internal\n");
 +            build_basic_mjpeg_vlc(s);
          }
      }
      if (avctx->field_order == AV_FIELD_BB) { /* quicktime icefloe 019 */
@@@ -969,12 -704,16 +988,15 @@@ static int ljpeg_decode_rgb_scan(MJpegD
  
      av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
                     (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));
+     if (!s->ljpeg_buffer)
+         return AVERROR(ENOMEM);
+ 
      buffer = s->ljpeg_buffer;
  
 -    for (i = 0; i < 3; i++)
 -        buffer[0][i] = 1 << (s->bits + point_transform - 1);
 +    for (i = 0; i < 4; i++)
 +        buffer[0][i] = 1 << (s->bits - 1);
  
      for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
 -        const int modified_predictor = mb_y ? predictor : 1;
          uint8_t *ptr = s->picture_ptr->data[0] + (linesize * mb_y);
  
          if (s->interlaced && s->bottom_field)
@@@ -2127,12 -1535,8 +2150,14 @@@ int ff_mjpeg_decode_frame(AVCodecContex
              ret = mjpeg_decode_com(s);
              if (ret < 0)
                  return ret;
 +        } else if (start_code == DQT) {
-             ff_mjpeg_decode_dqt(s);
++            ret = ff_mjpeg_decode_dqt(s);
++            if (ret < 0)
++                return ret;
          }
  
 +        ret = -1;
 +
          if (!CONFIG_JPEGLS_DECODER &&
              (start_code == SOF48 || start_code == LSE)) {
              av_log(avctx, AV_LOG_ERROR, "JPEG-LS support not enabled.\n");
@@@ -2245,18 -1632,22 +2270,19 @@@ eoi_parser
  
              goto the_end;
          case SOS:
 -            if (!s->got_picture) {
 -                av_log(avctx, AV_LOG_WARNING,
 -                       "Can not process SOS before SOF, skipping\n");
 +            s->cur_scan++;
 +            if (avctx->skip_frame == AVDISCARD_ALL) {
 +                skip_bits(&s->gb, get_bits_left(&s->gb));
                  break;
 -                }
 -            if ((ret = ff_mjpeg_decode_sos(s, NULL, NULL)) < 0 &&
 +            }
 +
 +            if ((ret = ff_mjpeg_decode_sos(s, NULL, 0, NULL)) < 0 &&
                  (avctx->err_recognition & AV_EF_EXPLODE))
 -                return ret;
 -            /* buggy avid puts EOI every 10-20th frame */
 -            /* if restart period is over process EOI */
 -            if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
 -                goto eoi_parser;
 +                goto fail;
              break;
          case DRI:
-             mjpeg_decode_dri(s);
+             if ((ret = mjpeg_decode_dri(s)) < 0)
+                 return ret;
              break;
          case SOF5:
          case SOF6:



More information about the ffmpeg-cvslog mailing list