From patchwork Wed Mar 6 13:47:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 12218 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B71CF446515 for ; Wed, 6 Mar 2019 15:47:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8FD5E68092B; Wed, 6 Mar 2019 15:47:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 66D1768092B for ; Wed, 6 Mar 2019 15:47:38 +0200 (EET) Received: from w2.tutanota.de (unknown [192.168.1.163]) by w4.tutanota.de (Postfix) with ESMTP id EDB671060237 for ; Wed, 6 Mar 2019 13:47:37 +0000 (UTC) Date: Wed, 6 Mar 2019 14:47:37 +0100 (CET) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] apedec: add ability to check CRC 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 6 Mar 2019, 11:22 by dev@lynne.ee: > The CRC flag is only signalled once every few minutes but CRC is still > always present so the patch uses the file version instead. > CRC on 24-bit files wants non-padded samples so skip such files. > Some corrupt samples may have been output before the final check > depending on the -max_samples setting. > v2 attached From 68c25bb026761eacda3c276148e2beb34e8929fd Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 6 Mar 2019 11:01:01 +0000 Subject: [PATCH v2] apedec: add ability to check CRC The CRC flag is only signalled once every few minutes but CRC is still always present so the patch uses the file version instead. CRC on 24-bit files wants non-padded samples so skip such files. Some corrupt samples may have been output before the final check depending on the -max_samples setting. --- libavcodec/apedec.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index 15eb416ba4..a20d884606 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -24,6 +24,7 @@ #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" +#include "libavutil/crc.h" #include "libavutil/opt.h" #include "lossless_audiodsp.h" #include "avcodec.h" @@ -147,7 +148,8 @@ typedef struct APEContext { int fset; ///< which filter set to use (calculated from compression level) int flags; ///< global decoder flags - uint32_t CRC; ///< frame CRC + uint32_t CRC; ///< signalled frame CRC + uint32_t CRC_state; ///< accumulated CRC int frameflags; ///< frame flags APEPredictor predictor; ///< predictor used for final reconstruction @@ -730,6 +732,7 @@ static int init_entropy_decoder(APEContext *ctx) /* Read the frame flags if they exist */ ctx->frameflags = 0; + ctx->CRC_state = UINT32_MAX; if ((ctx->fileversion > 3820) && (ctx->CRC & 0x80000000)) { ctx->CRC &= ~0x80000000; @@ -1548,6 +1551,27 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data, s->samples -= blockstodecode; + if ((avctx->err_recognition & AV_EF_CRCCHECK) && + (s->fileversion >= 3900) && (s->bps < 24)) { + uint32_t crc = s->CRC_state; + const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE); + for (i = 0; i < blockstodecode; i++) { + for (ch = 0; ch < s->channels; ch++) { + uint8_t *smp = frame->data[ch] + (i*(s->bps >> 3)); + crc = av_crc(crc_tab, crc, smp, s->bps >> 3); + } + } + + if (!s->samples && ((~crc >> 1) ^ s->CRC)) { + av_log(avctx, AV_LOG_ERROR, "CRC mismatch! Previously decoded " + "frames may have been affected as well.\n"); + if (avctx->err_recognition & AV_EF_EXPLODE) + return AVERROR_INVALIDDATA; + } + + s->CRC_state = crc; + } + *got_frame_ptr = 1; return !s->samples ? avpkt->size : 0; -- 2.21.0