[FFmpeg-devel] [PATCH 8/8] Ensure that more strict error checking also enables the less strict cases

Michael Niedermayer michaelni at gmx.at
Mon Oct 28 16:54:43 CET 2013


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavcodec/ac3dec.c        |    4 ++--
 libavcodec/alsdec.c        |    8 ++++----
 libavcodec/avcodec.h       |    2 ++
 libavcodec/flacdec.c       |    4 ++--
 libavcodec/h261dec.c       |    2 +-
 libavcodec/hevc.c          |    4 ++--
 libavcodec/ituh263dec.c    |    2 +-
 libavcodec/mpeg12dec.c     |    8 ++++----
 libavcodec/mpeg4videodec.c |    2 +-
 libavcodec/mpegaudiodec.c  |    4 ++--
 libavcodec/msmpeg4dec.c    |    2 +-
 libavcodec/takdec.c        |    4 ++--
 libavcodec/wavpack.c       |    8 ++++----
 13 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index f3842f6..849328d 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1325,12 +1325,12 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
         if (s->frame_size > buf_size) {
             av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
             err = AAC_AC3_PARSE_ERROR_FRAME_SIZE;
-        } else if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) {
+        } else if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL_MASK)) {
             /* check for crc mismatch */
             if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2],
                        s->frame_size - 2)) {
                 av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n");
-                if (avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL))
+                if (avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL_MASK))
                     return AVERROR_INVALIDDATA;
                 err = AAC_AC3_PARSE_ERROR_CRC;
             }
diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index 277873b..22859d7 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -401,7 +401,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
         if (get_bits_left(&gb) < 32)
             return AVERROR_INVALIDDATA;
 
-        if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) {
+        if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL_MASK)) {
             ctx->crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
             ctx->crc       = 0xFFFFFFFF;
             ctx->crc_org   = ~get_bits_long(&gb, 32);
@@ -1514,7 +1514,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     }
 
     // update CRC
-    if (sconf->crc_enabled && (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL))) {
+    if (sconf->crc_enabled && (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL_MASK))) {
         int swap = HAVE_BIGENDIAN != sconf->msb_first;
 
         if (ctx->avctx->bits_per_raw_sample == 24) {
@@ -1565,7 +1565,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
         if (ctx->cur_frame_length != sconf->frame_length &&
             ctx->crc_org != ctx->crc) {
             av_log(avctx, AV_LOG_ERROR, "CRC error.\n");
-            if (avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL))
+            if (avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL_MASK))
                 return AVERROR_INVALIDDATA;
         }
     }
@@ -1754,7 +1754,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     // allocate crc buffer
     if (HAVE_BIGENDIAN != sconf->msb_first && sconf->crc_enabled &&
-        (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL))) {
+        (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL_MASK))) {
         ctx->crc_buffer = av_malloc(sizeof(*ctx->crc_buffer) *
                                     ctx->cur_frame_length *
                                     avctx->channels *
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index f7be037..65c5e62 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2490,6 +2490,8 @@ typedef struct AVCodecContext {
 #define AV_EF_COMPLIANT  (1<<17)        ///< consider all spec non compliancies as errors
 #define AV_EF_AGGRESSIVE (1<<18)        ///< consider things that a sane encoder should not do as an error
 
+#define AV_EF_COMPLIANT_MASK (AV_EF_COMPLIANT|AV_EF_AGGRESSIVE)
+#define AV_EF_CAREFUL_MASK   (AV_EF_CAREFUL|AV_EF_COMPLIANT_MASK)
 
     /**
      * opaque 64bit number (generally a PTS) that will be reordered and
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index f62b313..2ec422e 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -539,11 +539,11 @@ static int flac_decode_frame(AVCodecContext *avctx, void *data,
     }
     bytes_read = get_bits_count(&s->gb)/8;
 
-    if ((s->avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_COMPLIANT)) &&
+    if ((s->avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_COMPLIANT_MASK)) &&
         av_crc(av_crc_get_table(AV_CRC_16_ANSI),
                0, buf, bytes_read)) {
         av_log(s->avctx, AV_LOG_ERROR, "CRC error at PTS %"PRId64"\n", avpkt->pts);
-        if (s->avctx->err_recognition & (AV_EF_EXPLODE|AV_EF_COMPLIANT))
+        if (s->avctx->err_recognition & (AV_EF_EXPLODE|AV_EF_COMPLIANT_MASK))
             return AVERROR_INVALIDDATA;
     }
 
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 5e45fc7..0477fdf 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -130,7 +130,7 @@ static int h261_decode_gob_header(H261Context *h)
 
     if (s->qscale == 0) {
         av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
-        if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
+        if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT_MASK))
             return -1;
     }
 
diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index e3e81ea..36649eb 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -2531,10 +2531,10 @@ static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output,
         return ret;
 
     /* verify the SEI checksum */
-    if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_COMPLIANT) && s->is_decoded &&
+    if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_COMPLIANT_MASK) && s->is_decoded &&
         s->is_md5) {
         ret = verify_md5(s, s->ref->frame);
-        if (ret < 0 && avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_COMPLIANT)) {
+        if (ret < 0 && avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_COMPLIANT_MASK)) {
             ff_hevc_unref_frame(s, s->ref, ~0);
             return ret;
         }
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 2cad21d..bc171a9 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -484,7 +484,7 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block,
             level = get_bits(&s->gb, 8);
             if((level&0x7F) == 0){
                 av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
-                if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
+                if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT_MASK))
                     return -1;
             }
             if (level == 255)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 82b503d..7e4f98f 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1321,7 +1321,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
     if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type == AV_PICTURE_TYPE_B) {
         s->full_pel[0] = get_bits1(&s->gb);
         f_code = get_bits(&s->gb, 3);
-        if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)))
+        if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT_MASK)))
             return -1;
         f_code += !f_code;
         s->mpeg_f_code[0][0] = f_code;
@@ -1330,7 +1330,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
     if (s->pict_type == AV_PICTURE_TYPE_B) {
         s->full_pel[1] = get_bits1(&s->gb);
         f_code = get_bits(&s->gb, 3);
-        if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)))
+        if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT_MASK)))
             return -1;
         f_code += !f_code;
         s->mpeg_f_code[1][0] = f_code;
@@ -1958,13 +1958,13 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
     if (width == 0 || height == 0) {
         av_log(avctx, AV_LOG_WARNING, "Invalid horizontal or vertical size "
                "value.\n");
-        if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
+        if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT_MASK))
             return AVERROR_INVALIDDATA;
     }
     s->aspect_ratio_info = get_bits(&s->gb, 4);
     if (s->aspect_ratio_info == 0) {
         av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n");
-        if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
+        if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT_MASK))
             return -1;
     }
     s->frame_rate_index = get_bits(&s->gb, 4);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 6de1735..fb6d757 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -537,7 +537,7 @@ static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
 
         if (code > 8){
             if(get_bits1(&s->gb)==0){ /* marker */
-                if(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT)){
+                if(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT_MASK)){
                     av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n");
                     return -1;
                 }
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index fc900d8..09a47be 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -968,7 +968,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
                 s_index -= 4;
                 skip_bits_long(&s->gb, last_pos - pos);
                 av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
-                if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
+                if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT_MASK))
                     s_index=0;
                 break;
             }
@@ -995,7 +995,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
     }
     /* skip extension bits */
     bits_left = end_pos2 - get_bits_count(&s->gb);
-    if (bits_left < 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_COMPLIANT))) {
+    if (bits_left < 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_COMPLIANT_MASK))) {
         av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
         s_index=0;
     } else if (bits_left > 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) {
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 7c260fe..dbe8236 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -838,7 +838,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
             i-= 192;
             if(i&(~63)){
                 const int left= get_bits_left(&s->gb);
-                if(((i+192 == 64 && level/qmul==-1) || !(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && left>=0){
+                if(((i+192 == 64 && level/qmul==-1) || !(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT_MASK))) && left>=0){
                     av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
                     i = 63;
                     break;
diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index fcbe10a..6dda476 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -686,7 +686,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_tak_decode_frame_header(avctx, gb, &s->ti, 0)) < 0)
         return ret;
 
-    if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_COMPLIANT)) {
+    if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_COMPLIANT_MASK)) {
         hsize = get_bits_count(gb) / 8;
         if (ff_tak_check_crc(pkt->data, hsize)) {
             av_log(avctx, AV_LOG_ERROR, "CRC error\n");
@@ -862,7 +862,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
     else if (get_bits_left(gb) > 0)
         av_log(avctx, AV_LOG_DEBUG, "underread\n");
 
-    if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_COMPLIANT)) {
+    if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_COMPLIANT_MASK)) {
         if (ff_tak_check_crc(pkt->data + hsize,
                              get_bits_count(gb) / 8 - hsize)) {
             av_log(avctx, AV_LOG_ERROR, "CRC error\n");
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index bd059f3..15db59f 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -487,9 +487,9 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb,
     } while (!last && count < s->samples);
 
     wv_reset_saved_context(s);
-    if (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL)) {
+    if (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL_MASK)) {
         int ret = wv_check_crc(s, crc, crc_extra_bits);
-        if (ret < 0 && s->avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL))
+        if (ret < 0 && s->avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL_MASK))
             return ret;
     }
 
@@ -550,9 +550,9 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb,
     } while (!last && count < s->samples);
 
     wv_reset_saved_context(s);
-    if (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL)) {
+    if (s->avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL_MASK)) {
         int ret = wv_check_crc(s, crc, crc_extra_bits);
-        if (ret < 0 && s->avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL))
+        if (ret < 0 && s->avctx->err_recognition & (AV_EF_EXPLODE | AV_EF_CAREFUL_MASK))
             return ret;
     }
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list