From patchwork Sat Mar 10 17:34:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 7891 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.181.170 with SMTP id m39csp2283828jaj; Sat, 10 Mar 2018 09:35:09 -0800 (PST) X-Google-Smtp-Source: AG47ELtilSUaMOx3IUc2cZfFiPRyA1bnYKIvLuMdcPwfl3QfTYLqcWASHJiFoOjkmspVfJrTV5aJ X-Received: by 10.223.160.42 with SMTP id k39mr227178wrk.138.1520703309503; Sat, 10 Mar 2018 09:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520703309; cv=none; d=google.com; s=arc-20160816; b=ATPR+pH+8OLr3A2BsbjViohDFXOiKdF5x73XemmVvgVkerMQA4j4Ga8yqC8gxCFBit /YYsRU4AKJT5LSKZqj5YA+tzUdT7aYGdFQdW5brIGrfj/kNiFOwjm4vORu2/FFQpZFUd h4t+b9/xwnZdK50I8JkRXRcmgEJ9a5RbahLFyDdJ8oIAvrJBqrCSCTlaFO25tQaJYHYe wfFMDy5nLgN8iXMd10RZhuvShKm5yG6UDAL/x3oOT2LltQzTscEFwLX5DDn7rbhNjrtk sUiuiGttDXqOHb2iwOojSHyOxOiwdEXjYhqjkejFDggRXWdrNDsRCFuYi606MBNF1dzp egjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=bolNeL3g0eIXxrHHIXCLq76WuLxeKCXIVuo4eojuDD8=; b=S+i2dDrWplnJZgFseH62WlwK7/Sh4OaHSL6zME8JCl2VJGHCcimdIl4Mz2dCIJK6Hp OmrR2RFS8TucHkZjEg6ptUxRo0IZqXiO4hAG0AEUq3fvFCH1ICge1H8jQjk3ilLhERAe lgmgSB+QzyrNhSs9iA/nQJaofk9UoQ5ZUZso2dD/Kou43oEtn6Awod1uE4/U6/lQjzV4 tmcFE5R2lnVwQ+dBorJ+2tdYCs9M/lEeanFrOPYkUAxRmmLm2d/ZEjoadWkqgp80J4H9 Uz5L370BP4s/1I09Gat+gig6pCc4AZXgiWUtk82OLZGlhD40yZKYqlNlgk7zyuSEhxP1 zJyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t193si925282wmd.135.2018.03.10.09.35.08; Sat, 10 Mar 2018 09:35:09 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5633A68A3F6; Sat, 10 Mar 2018 19:34:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe01-1.mx.upcmail.net (vie01a-qmta-pe01-1.mx.upcmail.net [62.179.121.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2EC1668A3C7 for ; Sat, 10 Mar 2018 19:34:51 +0200 (EET) Received: from [172.31.218.46] (helo=vie01a-dmta-pe06-1.mx.upcmail.net) by vie01a-pqmta-pe01.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1euiOa-0006bJ-5G for ffmpeg-devel@ffmpeg.org; Sat, 10 Mar 2018 18:35:00 +0100 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1euiOU-0001wt-FS for ffmpeg-devel@ffmpeg.org; Sat, 10 Mar 2018 18:34:54 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id LHap1x0020S5wYM01Haq2e; Sat, 10 Mar 2018 18:34:50 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 10 Mar 2018 18:34:28 +0100 Message-Id: <20180310173428.17293-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.16.2 Subject: [FFmpeg-devel] [PATCH] avcodec/mpeg4videodec: Use more specific error codes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer --- libavcodec/mpeg4videodec.c | 100 +++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 19210d97fe..1357b357a8 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -448,7 +448,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx) /* is there enough space left for a video packet + header */ if (get_bits_count(&s->gb) > s->gb.size_in_bits - 20) - return -1; + return AVERROR_INVALIDDATA; for (len = 0; len < 32; len++) if (get_bits1(&s->gb)) @@ -456,7 +456,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx) if (len != ff_mpeg4_get_video_packet_prefix_length(s)) { av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n"); - return -1; + return AVERROR_INVALIDDATA; } if (ctx->shape != RECT_SHAPE) { @@ -468,7 +468,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx) if (mb_num >= s->mb_num || !mb_num) { av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num); - return -1; + return AVERROR_INVALIDDATA; } s->mb_x = mb_num % s->mb_width; @@ -597,7 +597,7 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr) if (code < 0 || code > 9 /* && s->nbit < 9 */) { av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); - return -1; + return AVERROR_INVALIDDATA; } if (code == 0) { @@ -620,7 +620,7 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr) if (get_bits1(&s->gb) == 0) { /* marker */ if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) { av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n"); - return -1; + return AVERROR_INVALIDDATA; } } } @@ -664,7 +664,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) if (cbpc < 0) { av_log(s->avctx, AV_LOG_ERROR, "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpc; } } while (cbpc == 8); @@ -684,7 +684,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) if (dc < 0) { av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; + return dc; } dir <<= 1; if (dc_pred_dir) @@ -736,7 +736,7 @@ try_again: if (cbpc < 0) { av_log(s->avctx, AV_LOG_ERROR, "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpc; } if (cbpc == 20) goto try_again; @@ -774,11 +774,11 @@ try_again: if (!s->mcsel) { mx = ff_h263_decode_motion(s, pred_x, s->f_code); if (mx >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; my = ff_h263_decode_motion(s, pred_y, s->f_code); if (my >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; } else { @@ -805,11 +805,11 @@ try_again: int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); mx = ff_h263_decode_motion(s, pred_x, s->f_code); if (mx >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; my = ff_h263_decode_motion(s, pred_y, s->f_code); if (my >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; mot_val[0] = mx; mot_val[1] = my; } @@ -850,7 +850,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) if (cbpy < 0) { av_log(s->avctx, AV_LOG_ERROR, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpy; } s->cbp_table[xy] |= cbpy << 2; @@ -865,7 +865,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) if (cbpy < 0) { av_log(s->avctx, AV_LOG_ERROR, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpy; } if (s->cbp_table[xy] & 8) @@ -878,7 +878,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) if (dc < 0) { av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; + return dc; } dir <<= 1; if (dc_pred_dir) @@ -897,7 +897,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) if (cbpy < 0) { av_log(s->avctx, AV_LOG_ERROR, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpy; } if (s->cbp_table[xy] & 8) @@ -924,6 +924,7 @@ int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx) { MpegEncContext *s = &ctx->m; int mb_num; + int ret; const int part_a_error = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR; const int part_a_end = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END; @@ -931,14 +932,14 @@ int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx) if (mb_num <= 0) { ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); - return -1; + return mb_num ? mb_num : AVERROR_INVALIDDATA; } if (s->resync_mb_x + s->resync_mb_y * s->mb_width + mb_num > s->mb_num) { av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n"); ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); - return -1; + return AVERROR_INVALIDDATA; } s->mb_num_left = mb_num; @@ -950,7 +951,7 @@ int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx) av_log(s->avctx, AV_LOG_ERROR, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y); - return -1; + return AVERROR_INVALIDDATA; } } else { while (show_bits(&s->gb, 10) == 1) @@ -959,17 +960,18 @@ int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx) av_log(s->avctx, AV_LOG_ERROR, "marker missing after first P partition at %d %d\n", s->mb_x, s->mb_y); - return -1; + return AVERROR_INVALIDDATA; } } ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x - 1, s->mb_y, part_a_end); - if (mpeg4_decode_partition_b(s, mb_num) < 0) { + ret = mpeg4_decode_partition_b(s, mb_num); + if (ret < 0) { if (s->pict_type == AV_PICTURE_TYPE_P) ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_DC_ERROR); - return -1; + return ret; } else { if (s->pict_type == AV_PICTURE_TYPE_P) ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, @@ -1008,7 +1010,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, } else { level = mpeg4_decode_dc(s, n, &dc_pred_dir); if (level < 0) - return -1; + return level; } block[0] = level; i = 0; @@ -1076,7 +1078,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, if (SHOW_UBITS(re, &s->gb, 1) == 0) { av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n"); - return -1; + return AVERROR_INVALIDDATA; } SKIP_CACHE(re, &s->gb, 1); @@ -1089,7 +1091,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, if (SHOW_UBITS(re, &s->gb, 1) == 0) { av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n"); - return -1; + return AVERROR_INVALIDDATA; } SKIP_CACHE(re, &s->gb, 1); @@ -1098,7 +1100,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, if (SHOW_UBITS(re, &s->gb, 5) != 0x10) { av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n"); - return -1; + return AVERROR_INVALIDDATA; } SKIP_CACHE(re, &s->gb, 5); @@ -1134,7 +1136,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n"); if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR)) - return -1; + return AVERROR_INVALIDDATA; } SKIP_CACHE(re, &s->gb, 1); @@ -1145,7 +1147,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n"); if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR)) - return -1; + return AVERROR_INVALIDDATA; } SKIP_COUNTER(re, &s->gb, 1 + 12 + 1); @@ -1158,16 +1160,16 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, const int run1= run - rl->max_run[last][abs_level] - 1; if (abs_level <= rl->max_level[last][run]) { av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); - return -1; + return AVERROR_INVALIDDATA; } if (s->error_recognition > FF_ER_COMPLIANT) { if (abs_level <= rl->max_level[last][run]*2) { av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); - return -1; + return AVERROR_INVALIDDATA; } if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) { av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); - return -1; + return AVERROR_INVALIDDATA; } } } @@ -1184,7 +1186,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale); - return -1; + return AVERROR_INVALIDDATA; } } level = level < 0 ? -2048 : 2047; @@ -1222,7 +1224,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, if (i & (~63)) { av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; + return AVERROR_INVALIDDATA; } block[scan_table[i]] = level; @@ -1319,7 +1321,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64]) av_log(s->avctx, AV_LOG_ERROR, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra); - return -1; + return AVERROR_INVALIDDATA; } cbp += cbp; } @@ -1387,7 +1389,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) if (cbpc < 0) { av_log(s->avctx, AV_LOG_ERROR, "mcbpc damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpc; } } while (cbpc == 20); @@ -1443,11 +1445,11 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) for (i = 0; i < 2; i++) { mx = ff_h263_decode_motion(s, pred_x, s->f_code); if (mx >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; my = ff_h263_decode_motion(s, pred_y / 2, s->f_code); if (my >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; s->mv[0][i][0] = mx; s->mv[0][i][1] = my; @@ -1460,12 +1462,12 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) mx = ff_h263_decode_motion(s, pred_x, s->f_code); if (mx >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; my = ff_h263_decode_motion(s, pred_y, s->f_code); if (my >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; s->mv[0][0][0] = mx; s->mv[0][0][1] = my; } @@ -1476,11 +1478,11 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y); mx = ff_h263_decode_motion(s, pred_x, s->f_code); if (mx >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; my = ff_h263_decode_motion(s, pred_y, s->f_code); if (my >= 0xffff) - return -1; + return AVERROR_INVALIDDATA; s->mv[0][i][0] = mx; s->mv[0][i][1] = my; mot_val[0] = mx; @@ -1536,7 +1538,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) mb_type = get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1); if (mb_type < 0) { av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n"); - return -1; + return mb_type; } mb_type = mb_type_b_map[mb_type]; if (modb2) { @@ -1647,7 +1649,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) if (cbpc < 0) { av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpc; } } while (cbpc == 8); @@ -1665,7 +1667,7 @@ intra: if (cbpy < 0) { av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; + return cbpy; } cbp = (cbpc & 3) | (cbpy << 2); @@ -1681,7 +1683,7 @@ intra: /* decode each block */ for (i = 0; i < 6; i++) { if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, 1, 0) < 0) - return -1; + return AVERROR_INVALIDDATA; cbp += cbp; } goto end; @@ -1690,7 +1692,7 @@ intra: /* decode each block */ for (i = 0; i < 6; i++) { if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, 0, 0) < 0) - return -1; + return AVERROR_INVALIDDATA; cbp += cbp; } @@ -1700,7 +1702,7 @@ end: int next = mpeg4_is_resync(ctx); if (next) { if (s->mb_x + s->mb_y*s->mb_width + 1 > next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) { - return -1; + return AVERROR_INVALIDDATA; } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next) return SLICE_END; @@ -1727,7 +1729,7 @@ static int mpeg4_decode_gop_header(MpegEncContext *s, GetBitContext *gb) if (!show_bits(gb, 23)) { av_log(s->avctx, AV_LOG_WARNING, "GOP header invalid\n"); - return -1; + return AVERROR_INVALIDDATA; } hours = get_bits(gb, 5); @@ -2636,7 +2638,7 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb) av_log(s->avctx, AV_LOG_VERBOSE, "frame skip %d\n", gb->size_in_bits); return FRAME_SKIPPED; // divx bug } else - return -1; // end of stream + return AVERROR_INVALIDDATA; // end of stream } /* use the bits after the test */