From patchwork Fri Mar 19 05:58:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26474 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 141A5449D11 for ; Fri, 19 Mar 2021 07:59:57 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C68BD68A64D; Fri, 19 Mar 2021 07:59:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7EE3268A68F for ; Fri, 19 Mar 2021 07:59:43 +0200 (EET) Received: by mail-ej1-f49.google.com with SMTP id b9so7753814ejc.11 for ; Thu, 18 Mar 2021 22:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=cptgBE2gkG9sEBGuSXg+3of/7b+uOvJBf4lhhrfoOtk=; b=lf1hW4CSkOHxsIgo6IlrRZ+CvUmCAvHxUbXoAxHyj/BM+3ikrhu/JuvVIwLNL3xpOB TOMPobKK9Y5aa1wYMjuYFxdMsHkVFcCIW30FFslLjtqiZPRBol+pJ2c+ENFJ48VQRuzT 5cvWFR7wwWHBjI+P3cuzgL3dSuc8bgSrDGj9vOdl6KiLS2TQ6X64olJuTfxq872o98Qp sq60rFU+OpOO0G06Ip9Lk8s+U9W6gyHUAtwKHXngXUJgMUaM5AbdqLR5UpVcFzNouREq vBwjnBJnUy6Fmy+BqmgCxOnt59L5LffIkKSv16HRvwGSt3L8ozLyUs4smlC1Q+cRMzHi 6V+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=cptgBE2gkG9sEBGuSXg+3of/7b+uOvJBf4lhhrfoOtk=; b=Ft3V9IBP+Lewg14BLEHTJoVHvQn1ATQpbjIKV53C5CbCB/KTMuBvFLWCanKEDGKr+t jyiQMbGXpu9OLJuaAtrjHt1jqQA8or5U+IECHnDNAEoEUHWyhrmVUH6xMICc2JJwmQts kVTGVtIwqUWJpnvHShCzvWn+CARVxfwjisBnD2XIAvHC04fhc07UNWlO0GTObrbmBlhH 53NE4lsJwsqiaUGaGRnsdhD3vU/7y5nspjLE6b1L6Zn7WiOkhKXxIv41hzLDA7tm4pAC ZWjGTdBjArJ3q0H0Do54W33zKaL666RFizMQUd2Ve4zDUjCXK9GQlBTkxP6fN6fgkHdH NQSg== X-Gm-Message-State: AOAM531nMRwAf5yz3kH+/e/E/76UiaeBmMzVvDd3aVUOfYcQWhj5+WWv jlxDmblfhwUlqb8mnN1PmkIBMf1kmKq9yQ== X-Google-Smtp-Source: ABdhPJxQDaeSs5SMRgOu6vDyyiBUXykIJYybni1ADITxfuY9Gt/XD+TYL23lHFn6v8wVxc9ph5Ng8A== X-Received: by 2002:a17:906:5e55:: with SMTP id b21mr2452795eju.289.1616133582799; Thu, 18 Mar 2021 22:59:42 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id x17sm3109344ejd.68.2021.03.18.22.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 22:59:42 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Mar 2021 06:58:55 +0100 Message-Id: <20210319055904.2264501-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319055904.2264501-1-andreas.rheinhardt@gmail.com> References: <20210319055904.2264501-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/18] avformat/ipmovie: Avoid reading packets during read_header 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" They will be discarded anyway because this can only happen for invalid data. This already implies that the pkt won't be used at all when parsing the very first chunk when reading the header, so one can use NULL as argument and remove the av_packet_unref() on error. Signed-off-by: Andreas Rheinhardt --- libavformat/ipmovie.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c index 26886d9592..3f40bb8fe8 100644 --- a/libavformat/ipmovie.c +++ b/libavformat/ipmovie.c @@ -47,6 +47,7 @@ #define CHUNK_SHUTDOWN 0x0004 #define CHUNK_END 0x0005 /* these last types are used internally */ +#define CHUNK_HAVE_PACKET 0xFFFB #define CHUNK_DONE 0xFFFC #define CHUNK_NOMEM 0xFFFD #define CHUNK_EOF 0xFFFE @@ -154,7 +155,7 @@ static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb, av_log(s->avf, AV_LOG_TRACE, "sending audio frame with pts %"PRId64" (%d audio frames)\n", pkt->pts, s->audio_frame_count); - chunk_type = CHUNK_VIDEO; + chunk_type = CHUNK_HAVE_PACKET; } else if (s->frame_format) { @@ -230,7 +231,7 @@ static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb, s->video_pts += s->frame_pts_inc; - chunk_type = CHUNK_VIDEO; + chunk_type = CHUNK_HAVE_PACKET; } else { @@ -602,10 +603,6 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb, /* make a note of where the stream is sitting */ s->next_chunk_offset = avio_tell(pb); - /* dispatch the first of any pending packets */ - if ((chunk_type == CHUNK_VIDEO) || (chunk_type == CHUNK_AUDIO_ONLY)) - chunk_type = load_ipmovie_packet(s, pb, pkt); - return chunk_type; } @@ -658,8 +655,7 @@ static int ipmovie_read_header(AVFormatContext *s) ipmovie->palette[i] = 0xFFU << 24; /* process the first chunk which should be CHUNK_INIT_VIDEO */ - if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO) { - av_packet_unref(&pkt); + if (process_ipmovie_chunk(ipmovie, pb, NULL) != CHUNK_INIT_VIDEO) { return AVERROR_INVALIDDATA; } @@ -708,6 +704,10 @@ static int ipmovie_read_packet(AVFormatContext *s, for (;;) { ret = process_ipmovie_chunk(ipmovie, pb, pkt); + /* dispatch the first of any pending packets */ + if ((ret == CHUNK_VIDEO) || (ret == CHUNK_AUDIO_ONLY)) + ret = load_ipmovie_packet(ipmovie, pb, pkt); + if (ret == CHUNK_BAD) ret = AVERROR_INVALIDDATA; else if (ret == CHUNK_EOF) @@ -716,7 +716,7 @@ static int ipmovie_read_packet(AVFormatContext *s, ret = AVERROR(ENOMEM); else if (ret == CHUNK_END || ret == CHUNK_SHUTDOWN) ret = AVERROR_EOF; - else if (ret == CHUNK_VIDEO) + else if (ret == CHUNK_HAVE_PACKET) ret = 0; else if (ret == CHUNK_INIT_VIDEO || ret == CHUNK_INIT_AUDIO) continue;