From patchwork Fri May 22 22:44:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 19808 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 2849844B3A9 for ; Sat, 23 May 2020 01:44:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0BDBF6882F0; Sat, 23 May 2020 01:44:51 +0300 (EEST) 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 8D7FA6808E8 for ; Sat, 23 May 2020 01:44:44 +0300 (EEST) Received: from w3.tutanota.de (unknown [192.168.1.164]) by w4.tutanota.de (Postfix) with ESMTP id 38BD71060160 for ; Fri, 22 May 2020 22:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1590187484; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=Lpn4Vic6c6yHrfZgd9IuSKkRHmr+39NtAdp2o2JkTPI=; b=rsdTjMUsioEAqwFEBVwPxf19hhsUIsPmG6+GaJfYPGW1H+e3oXP1/wygz8sV0F4g M2wIJErt1G1ex5yO5kbuju04Ddp0hPuu/ZLwYIRLPWz41bkTCBcJFo3AsvFugr6rwcc b/fbWscvYsNvaQYdWdr5D43WJELBoCrlwzDsa+1Yh5C4D2NR8WrqU8epkz4cMSAn8FS irg0wMycHR465hejHYVWc3uVcB1uZTpiEIdQL2D6UrcfeGHV/fMh6ubNhRgyMHUcWEf T6B/ycVmKFISUeB3hFHiFhF/V27iDys2FQUjOp0krNEz2fZwDpRC+KGRviG12RyHoN9 bFOqlcVdWQ== Date: Sat, 23 May 2020 00:44:44 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] mpegaudiodec_template: 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" Posting this again. A lot of files have CRC included. The CRC only covers 34 bytes at most from the frame but it should still be enough for some amount of error detection. Patch attached. Subject: [PATCH 2/3] mpegaudiodec_template: add ability to check CRC A lot of files have CRC included. The CRC only covers 34 bytes at most from the frame but it should still be enough for some amount of error detection. --- libavcodec/mpegaudiodec_template.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c index 3f1674e827..3d7e3ba4f2 100644 --- a/libavcodec/mpegaudiodec_template.c +++ b/libavcodec/mpegaudiodec_template.c @@ -27,6 +27,7 @@ #include "libavutil/attributes.h" #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" +#include "libavutil/crc.h" #include "libavutil/float_dsp.h" #include "libavutil/libm.h" #include "avcodec.h" @@ -1565,9 +1566,22 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples, init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8); - /* skip error protection field */ - if (s->error_protection) - skip_bits(&s->gb, 16); + if (s->error_protection) { + uint16_t crc = get_bits(&s->gb, 16); + if (s->err_recognition & AV_EF_CRCCHECK) { + const int sec_len = s->lsf ? ((s->nb_channels == 1) ? 9 : 17) : + ((s->nb_channels == 1) ? 17 : 32); + const AVCRC *crc_tab = av_crc_get_table(AV_CRC_16_ANSI); + uint32_t crc_cal = av_crc(crc_tab, UINT16_MAX, &buf[2], 2); + crc_cal = av_crc(crc_tab, crc_cal, &buf[6], sec_len); + + if (av_bswap16(crc) ^ crc_cal) { + av_log(s->avctx, AV_LOG_ERROR, "CRC mismatch!\n"); + if (s->err_recognition & AV_EF_EXPLODE) + return AVERROR_INVALIDDATA; + } + } + } switch(s->layer) { case 1: