From patchwork Tue Jul 11 17:12:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42595 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp1600761pzb; Tue, 11 Jul 2023 10:12:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlEAube/z7LONoqp4KoDIDIIeNztQLrzpOjH4VazOW1hUBO9luBZp7aGAQ2N4QeC9GS3Q1NF X-Received: by 2002:a05:6402:350:b0:51e:bc7:58e6 with SMTP id r16-20020a056402035000b0051e0bc758e6mr16499584edw.15.1689095565069; Tue, 11 Jul 2023 10:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689095565; cv=none; d=google.com; s=arc-20160816; b=KDSsDjZgh2vwZqXKXc6ehgU/KtRYgeJnLaY7Ge48QMg3TWsP8gMlAH6uaa1S+TO5Fs A6IhhGUuBNIONSeWgeD0QcbAdIELE63vMnwjocJ85NtYc1ix5Rsr6HeM8jdOE70GO4WP CXoMls926BbNovFuGiNjFujmWTfa2t3kRaTq7pssK4Zj0MH0oDlB07APnGnZLR7JvmDZ puDxkgagaeUQQ6e12urqJloyuDHp/y++OJ5SOX+t0pG5ulssWNCcsLgCMaRpm8eO90GS PXZ/v0p5WkBW1Gxc01l8z0swK7eNgDPY9ZyaqaOgOYhtLgkIwJicps/vGSGZ0CzcZsnb WW+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=fabaPocq2ka0pyPmHrEsSsT0ULJJrG/Jn1BPElmLvrg=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=SsxRv2kaZ7a9WmKgTbsCmrtMp0ISomn267kzX3iKS9TT2VE/2lxWazFHptnm0yR6Th 04V/I0tYrkEhuw/EhTodfmW9TXWkzO/B5okBH20S478yXG9q8w3PZIu0a9/wKaNdD50a ahlqBkayL4OpcfnfqwPhQx0TvCvm6w01HRk0jBUOZOEiZ7pP5cVhD0uXgg9sO3oukbwv +ewSSPcy2G+Qny49vGY6emR+FE1XX1x5LYIU8a5qbULjULyJ7u3XQlVgXkpIcfxl8kd0 5YGirFefTu5bDigL4NQaE9H16Uhsr7DtXGGU3r9c4JyCCTcDzUVZyaRG4JH5tq7D0+Q6 gTcw== 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 n1-20020a05640206c100b0051e33b5ee68si2707750edy.250.2023.07.11.10.12.44; Tue, 11 Jul 2023 10:12:45 -0700 (PDT) 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 3FFA168C32F; Tue, 11 Jul 2023 20:12:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4B35068C32F for ; Tue, 11 Jul 2023 20:12:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F29422404EC for ; Tue, 11 Jul 2023 19:12:33 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id sN4ZVpHo4vdi for ; Tue, 11 Jul 2023 19:12:33 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6362A2404EA for ; Tue, 11 Jul 2023 19:12:33 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A87313A0153 for ; Tue, 11 Jul 2023 19:12:24 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jul 2023 19:12:23 +0200 Message-Id: <20230711171223.11878-1-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/gifdec: unify get_buffer() calls I/P frames X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: HSAs2fwKTrBH Always call ff_reget_buffer(), which ensures that get_buffer2() is called with AV_GET_BUFFER_FLAG_REF. Fixes #10460. --- libavcodec/gifdec.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c index f2ab783ef0..af65baabd5 100644 --- a/libavcodec/gifdec.c +++ b/libavcodec/gifdec.c @@ -489,29 +489,22 @@ static int gif_decode_frame(AVCodecContext *avctx, AVFrame *rframe, return ret; av_frame_unref(s->frame); - if ((ret = ff_get_buffer(avctx, s->frame, 0)) < 0) - return ret; - av_fast_malloc(&s->idx_line, &s->idx_line_size, s->screen_width); if (!s->idx_line) return AVERROR(ENOMEM); - - s->frame->pict_type = AV_PICTURE_TYPE_I; - s->frame->flags |= AV_FRAME_FLAG_KEY; - s->keyframe_ok = 1; - } else { - if (!s->keyframe_ok) { - av_log(avctx, AV_LOG_ERROR, "cannot decode frame without keyframe\n"); - return AVERROR_INVALIDDATA; - } - - if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0) - return ret; - - s->frame->pict_type = AV_PICTURE_TYPE_P; - s->frame->flags &= ~AV_FRAME_FLAG_KEY; + } else if (!s->keyframe_ok) { + av_log(avctx, AV_LOG_ERROR, "cannot decode frame without keyframe\n"); + return AVERROR_INVALIDDATA; } + ret = ff_reget_buffer(avctx, s->frame, 0); + if (ret < 0) + return ret; + + s->frame->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; + s->frame->flags = AV_FRAME_FLAG_KEY * s->keyframe; + s->keyframe_ok |= !!s->keyframe; + ret = gif_parse_next_image(s, s->frame); if (ret < 0) return ret;