From patchwork Tue Mar 16 20:30: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: 26415 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 7D6434487CA for ; Tue, 16 Mar 2021 22:31:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 475EE68AFB5; Tue, 16 Mar 2021 22:31:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E507968AF1C for ; Tue, 16 Mar 2021 22:31:07 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id e19so74440596ejt.3 for ; Tue, 16 Mar 2021 13:31:07 -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:reply-to:mime-version :content-transfer-encoding; bh=ueQ/0tQfDEDxUsWvRLV+24lLJLm7egnEDHpBWUDM9+Q=; b=aeueLgem2gJijs3+bfwI8nTyAXRok0wV9TxSaffhWO5yxigy0kpmyXuSCKz+kz6mRE V4SzzvAq690E0mtoO3Dkf2rKUZJZ+BN1MmIRFCi/l2pJUEH5LMbT2ThV6ZwXVEmObhGb t0Vje72uZb53Ra5QNlZmU2zzAi4xrhrnBc24NogC/RUhLNwhEYGT+qOsdYOD5+loixot Iajlo0d+JIQMUWAzcHmjOjYrnxDS6jVumJFsCD+wREMyIPVAETj4TSUm2eZ6KNybXWDN Z0t6AxSrSClC0ZEOh+MnFsfbmgZjbODfU9+RVuy97QeKCouPpJv1EZ28PVUMfV733/bH JU2A== 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:reply-to :mime-version:content-transfer-encoding; bh=ueQ/0tQfDEDxUsWvRLV+24lLJLm7egnEDHpBWUDM9+Q=; b=rEBI4Aj2D/uJrq+yGk9vI6cgRgQye0thJ3+C4XpbwcOhe8nlyVqhWxvnAU23tNazHZ 9sQh9O4QQaUcupCgfFtp5wylW3O6TC6NdzGNtd2vQ6ypcek3CqzJye393khY9tfyb7BS 1X50lIsgo+ERp9VkXI7ABShBDpbpgBmFDd2OP0/vOtc1MuGi6obDT2iv6auJZ+e6AiG9 2dlqRN3ZqQxQ5kqjSlylgPHa/KEoZpL9b2sqh3qMO9HYLfVBoutQJzMo0M2dIEFzihuM ut2tGTG06naw0efw8+nECBiZB3mO31Y6Ve7EIMABwnDRkbOn31DqShLdLRaHA9mXm31V le3A== X-Gm-Message-State: AOAM530qZ4GQW9VO7NRajegUo/dUa+HUlNsmJYRV1XI99qa4GEiv46/I gKwS9Dcu3lkfMha1qHEppB70w8BvDi71cA== X-Google-Smtp-Source: ABdhPJwLHv1xkJQAMf1kw7ioF36+ji3VVFFeWm4Xi6z2xS06uMphKq/B+Ef6rA+E5/RCHKxLHufQxw== X-Received: by 2002:a17:906:4117:: with SMTP id j23mr32444384ejk.10.1615926667231; Tue, 16 Mar 2021 13:31:07 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id a22sm10281908ejr.89.2021.03.16.13.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 13:31:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Mar 2021 21:30:55 +0100 Message-Id: <20210316203100.528950-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] avcodec/utils: Check earlier for codec id/type mismatch 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" These fields can't be set via AVOptions, ergo one can check them before having allocated anything. Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 71dbcb19d8..2bc556c1d9 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -564,6 +564,18 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (!codec) codec = avctx->codec; + if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && + avctx->codec_id == AV_CODEC_ID_NONE) { + avctx->codec_type = codec->type; + avctx->codec_id = codec->id; + } + if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type && + avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { + av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); + return AVERROR(EINVAL); + } + avctx->codec = codec; + if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); @@ -682,18 +694,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code goto free_and_end; } - avctx->codec = codec; - if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && - avctx->codec_id == AV_CODEC_ID_NONE) { - avctx->codec_type = codec->type; - avctx->codec_id = codec->id; - } - if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type - && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { - av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); - ret = AVERROR(EINVAL); - goto free_and_end; - } avctx->frame_number = 0; avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);