From patchwork Sat Jul 25 18:02:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 21258 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 0834F449DAD for ; Sat, 25 Jul 2020 21:03:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DBB8868AE82; Sat, 25 Jul 2020 21:03:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D0776880BE for ; Sat, 25 Jul 2020 21:03:41 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1jzOWL-0009V1-08 for ffmpeg-devel@ffmpeg.org; Sat, 25 Jul 2020 20:03:41 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id zOVMjfGfrIr7GzOVMjZfXV; Sat, 25 Jul 2020 20:02:41 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=QN4WuTDL c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=BbyLWh3mfAXbmlvOme4A:9 a=I4CtC81dskcxO2hk:21 a=_h1AcEcIHV9kEdHK:21 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 25 Jul 2020 20:02:40 +0200 Message-Id: <20200725180240.7122-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfP7KdefT747aQvxifc7Gy8GP13Zgs9fYFzl+BYZ0CbCttKHpy5IwehO2b1nGGpWgwZGxfqcwg+TMHdjyRsyOeDAZ6ixe7rhVB3Gojco2o0IgdFPb1xC9 3DTk7nFNpVmYumnMU3qGC8vYBDd7YYDiCyN91f/LOJVQ9IdjMa/qPmyk Subject: [FFmpeg-devel] [PATCH] avformat/ape: Remove seektable and bittable 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" Suggested-by: Andreas Signed-off-by: Michael Niedermayer --- libavformat/ape.c | 75 ++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/libavformat/ape.c b/libavformat/ape.c index d92cb2867d..2698c770ee 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -77,10 +77,6 @@ typedef struct APEContext { uint16_t bps; uint16_t channels; uint32_t samplerate; - - /* Seektable */ - uint32_t *seektable; - uint8_t *bittable; } APEContext; static int ape_read_close(AVFormatContext * s); @@ -130,20 +126,6 @@ static void ape_dumpinfo(AVFormatContext * s, APEContext * ape_ctx) av_log(s, AV_LOG_DEBUG, "\nSeektable\n\n"); if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) { av_log(s, AV_LOG_DEBUG, "No seektable\n"); - } else { - for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) { - if (i < ape_ctx->totalframes - 1) { - av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32" (%"PRIu32" bytes)", - i, ape_ctx->seektable[i], - ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]); - if (ape_ctx->bittable) - av_log(s, AV_LOG_DEBUG, " + %2d bits\n", - ape_ctx->bittable[i]); - av_log(s, AV_LOG_DEBUG, "\n"); - } else { - av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32"\n", i, ape_ctx->seektable[i]); - } - } } av_log(s, AV_LOG_DEBUG, "\nFrames\n\n"); @@ -262,10 +244,10 @@ static int ape_read_header(AVFormatContext * s) ape->totalframes); return AVERROR_INVALIDDATA; } - if (ape->seektablelength / sizeof(*ape->seektable) < ape->totalframes) { + if (ape->seektablelength / sizeof(uint32_t) < ape->totalframes) { av_log(s, AV_LOG_ERROR, "Number of seek entries is less than number of frames: %"SIZE_SPECIFIER" vs. %"PRIu32"\n", - ape->seektablelength / sizeof(*ape->seektable), ape->totalframes); + ape->seektablelength / sizeof(uint32_t), ape->totalframes); return AVERROR_INVALIDDATA; } ape->frames = av_malloc_array(ape->totalframes, sizeof(APEFrame)); @@ -281,39 +263,26 @@ static int ape_read_header(AVFormatContext * s) if (ape->totalframes > 1) ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1); - if (ape->seektablelength > 0) { - ape->seektable = av_mallocz(ape->seektablelength); - if (!ape->seektable) { - ret = AVERROR(ENOMEM); - goto fail; - } - for (i = 0; i < ape->seektablelength / sizeof(uint32_t) && !pb->eof_reached; i++) - ape->seektable[i] = avio_rl32(pb); - if (ape->fileversion < 3810) { - ape->bittable = av_mallocz(ape->totalframes); - if (!ape->bittable) { - ret = AVERROR(ENOMEM); - goto fail; - } - for (i = 0; i < ape->totalframes && !pb->eof_reached; i++) - ape->bittable[i] = avio_r8(pb); - } - if (pb->eof_reached) { - av_log(s, AV_LOG_ERROR, "File truncated\n"); - ret = AVERROR_INVALIDDATA; - goto fail; - } - } - ape->frames[0].pos = ape->firstframe; ape->frames[0].nblocks = ape->blocksperframe; ape->frames[0].skip = 0; + avio_rl32(pb); // seektable[0] for (i = 1; i < ape->totalframes; i++) { - ape->frames[i].pos = ape->seektable[i] + ape->junklength; + uint32_t seektable_entry = avio_rl32(pb); + ape->frames[i].pos = seektable_entry + ape->junklength; ape->frames[i].nblocks = ape->blocksperframe; ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos; ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3; + + if (pb->eof_reached) { + av_log(s, AV_LOG_ERROR, "seektable truncated\n"); + ret = AVERROR_INVALIDDATA; + goto fail; + } + ff_dlog(s, "seektable: %8d %"PRIu32"\n", i, seektable_entry); } + avio_skip(pb, ape->seektablelength / sizeof(uint32_t) - ape->totalframes); + ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks; /* calculate final packet size from total file size, if available */ file_size = avio_size(pb); @@ -335,10 +304,18 @@ static int ape_read_header(AVFormatContext * s) } if (ape->fileversion < 3810) { for (i = 0; i < ape->totalframes; i++) { - if (i < ape->totalframes - 1 && ape->bittable[i + 1]) - ape->frames[i].size += 4; + int bits = avio_r8(pb); + if (i && bits) + ape->frames[i - 1].size += 4; + ape->frames[i].skip <<= 3; - ape->frames[i].skip += ape->bittable[i]; + ape->frames[i].skip += bits; + ff_dlog(s, "bittable: %2d\n", bits); + if (pb->eof_reached) { + av_log(s, AV_LOG_ERROR, "bittable truncated\n"); + ret = AVERROR_INVALIDDATA; + goto fail; + } } } @@ -454,8 +431,6 @@ static int ape_read_close(AVFormatContext * s) APEContext *ape = s->priv_data; av_freep(&ape->frames); - av_freep(&ape->seektable); - av_freep(&ape->bittable); return 0; }