From patchwork Sat May 14 20:55:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35768 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp876571pzb; Sat, 14 May 2022 13:55:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjsfxMfbinl9HE/iFTWR4yCu7PQjSBz6QvHtKh1IiVueLEqb2A7UCpdgs5voW9Hr3BpEnc X-Received: by 2002:a17:906:804b:b0:6f3:8d78:ffa8 with SMTP id x11-20020a170906804b00b006f38d78ffa8mr9270770ejw.588.1652561759408; Sat, 14 May 2022 13:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652561759; cv=none; d=google.com; s=arc-20160816; b=rY5loBHTvW0TMwWIWn/sIcMss5BXaCRogrb2WYHOCYW/0u9+qYDoeuEOZ/baUP3dwI HoQQzHfNlZwFiWQSgjnGOIdncRtIV0AW5qFcIJwzs+iMeX6jEf7JDag1XhlzUdez1f1h stculWGwnXrPF1HaqfER03kl1kPrco0euYeHCratJW+eDHKcED7Hn3rqYzT5G2tlEBxb ZayCoJ2NvofDc9Pxqf+ZUEhSQMV//sRAQ3Y8ZsaXCpLFVWTH362b4FyTXkXbRZHb1MIN nip43WoTk438xCTbbBC8o3mj90nCINg3+E5lZQ4tGmQTYEdUK2oD8DB5vDcCARjeQvF2 Lzjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=FbmSkekbRU+glvbDuDDew4IRVICf+5nKzfH20HB12ZI=; b=1AL3dWGRUJ9FlUwrSzwlQc6ko4qWqKXv5/pDsfa/Q2bfCrsx2RRbjZWsu7GhbgRSHu TbXLYrrZGfWF+wYmoPWujEbGBatHCsQcvupfaasK6rxOgInZ0jG7wMLqluB+tM8YAClS LW2Ia8ZcgCJACN8tbaM1Fc8TVIEfBRKHHttx3TzK7juW7F+cEf3r9UoQtk01ckE2yzVA iH5yJXlhWYbGjXaLZaekkNFumhuAZNagmWXpOHR/IlIPmi5RfHoiu5i1mMtKW6vHpew0 dgd8A9mgA3mW5uK9Apd127Xhs3l7aA4S7+xEaw9jAh1LdQucyZz7DWuutl5C8DlEACD1 gK6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=m+qE9ddF; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t16-20020a056402525000b00425e9509cd3si6732867edd.60.2022.05.14.13.55.59; Sat, 14 May 2022 13:55:59 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=m+qE9ddF; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 298CE68B44F; Sat, 14 May 2022 23:55:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C3D9968B460 for ; Sat, 14 May 2022 23:55:28 +0300 (EEST) Received: by mail-pf1-f181.google.com with SMTP id y41so10645160pfw.12 for ; Sat, 14 May 2022 13:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=e9kAy1hNhj5Sc7aTm650SFJdxjeG7UpvPDKX1g2Yhyg=; b=m+qE9ddFtaM8QKira6LaTNhEp97Qnm9B/D1HcM/kbPCmdrhDy1Q8bHnXvAokUfwTHp ljvYGHEvqrlxInJWmi+Pu09r/4J1AdCs6SmvHYSI+tOx2fuvnfbmkLxgpjAyMo9UKW6A dex64BYPn9df8QPuXUqUFwmRzdf3wWcplqRpUb21anVKg49D5RQaqRpjQmN41+BSdqMm mxmG3qsGWFsMhcwo/SOHje1EPNPetmIH1xaMU7ErWWC4mSQr07k8xOjVCo85wTaY/7da +wqbizkDFWW+BjdUA2YEuI+jMEFfDAJJ2TAj6WskX33pulKJwRD9v+1WWUOgnBfgLhIe H4tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=e9kAy1hNhj5Sc7aTm650SFJdxjeG7UpvPDKX1g2Yhyg=; b=WhMzqxhIIiuiDxwHule1pIqpcNOzy0mb08Tti9TR3BIaPCLkCZ8f17R2ZHxxZopH7v R/pLc/hd/vHkCIphbquNwl56eDG/EBmYUYqDTDWZrC/EvRTBlOI4XG8gkDv65K0hEfiL lhUe8Km19R0W2eX8TpwCvWAA8xLip19pHPK8gScVWu8f7skgefBX+cdrlEV5hzupbo0A b+02Mo6HzX18pHP+v7LVn3EJNst78ZQKppUEqDsZXhodCLKPEzsb12at+T+Eaq7anAA4 ycyPjqUKXlsIO+L7CGs/LAH5nV76mTx0as1/0t+qfsubCFXVwm4RH/j88GdO7MCdqYMs 5+FA== X-Gm-Message-State: AOAM531/fpLlB+8zVW5poSFc20flFY6FAmqck3TllL7wgXVEUPTzheAh v7XrgqgUTm7QHo2PudEetbafkxuAmo33jg== X-Received: by 2002:a63:8548:0:b0:3db:2f3:d2fd with SMTP id u69-20020a638548000000b003db02f3d2fdmr9217217pgd.519.1652561726421; Sat, 14 May 2022 13:55:26 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id ip14-20020a17090b314e00b001d81a30c437sm3629712pjb.50.2022.05.14.13.55.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 May 2022 13:55:25 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <5acab7b52b7f6e83023cb023ce9b616515d3ed4c.1652561722.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Sat, 14 May 2022 20:55:14 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v4 02/10] libavformat/asfdec: fix get_value return type and add checks for 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 Cc: Michael Niedermayer , softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sPMR4ivyFV8R From: softworkz unsupported values get_value had a return type of int, which means that reading QWORDS (case 4) was broken due to truncation of the result from avio_rl64(). Signed-off-by: softworkz --- libavformat/asfdec_f.c | 57 +++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index 4770a812db..c7c4ba55d6 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -203,7 +203,7 @@ static int asf_probe(const AVProbeData *pd) /* size of type 2 (BOOL) is 32bit for "Extended Content Description Object" * but 16 bit for "Metadata Object" and "Metadata Library Object" */ -static int get_value(AVIOContext *pb, int type, int type2_size) +static uint64_t get_value(AVIOContext *pb, int type, int type2_size) { switch (type) { case ASF_BOOL: @@ -549,6 +549,8 @@ static int asf_read_ext_content_desc(AVFormatContext *s) { AVIOContext *pb = s->pb; ASFContext *asf = s->priv_data; + uint64_t dar_num = 0; + uint64_t dar_den = 0; int desc_count, i, ret; desc_count = avio_rl16(pb); @@ -568,14 +570,27 @@ static int asf_read_ext_content_desc(AVFormatContext *s) /* My sample has that stream set to 0 maybe that mean the container. * ASF stream count starts at 1. I am using 0 to the container value * since it's unused. */ - if (!strcmp(name, "AspectRatioX")) - asf->dar[0].num = get_value(s->pb, value_type, 32); - else if (!strcmp(name, "AspectRatioY")) - asf->dar[0].den = get_value(s->pb, value_type, 32); + if (!strcmp(name, "AspectRatioX")) { + dar_num = get_value(s->pb, value_type, 32); + if (dar_num > INT64_MAX) { + av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioX value: %"PRIu64"\n", dar_num); + return AVERROR(ENOTSUP); + } + } + else if (!strcmp(name, "AspectRatioY")) { + dar_den = get_value(s->pb, value_type, 32); + if (dar_den > INT64_MAX) { + av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioY value: %"PRIu64"\n", dar_den); + return AVERROR(ENOTSUP); + } + } else get_tag(s, name, value_type, value_len, 32); } + if (dar_num && dar_den) + av_reduce(&asf->dar[0].num, &asf->dar[0].den, dar_num, dar_den, INT_MAX); + return 0; } @@ -603,6 +618,8 @@ static int asf_read_metadata(AVFormatContext *s) { AVIOContext *pb = s->pb; ASFContext *asf = s->priv_data; + uint64_t dar_num[128] = {0}; + uint64_t dar_den[128] = {0}; int n, stream_num, name_len_utf16, name_len_utf8, value_len; int ret, i; n = avio_rl16(pb); @@ -630,17 +647,29 @@ static int asf_read_metadata(AVFormatContext *s) av_log(s, AV_LOG_TRACE, "%d stream %d name_len %2d type %d len %4d <%s>\n", i, stream_num, name_len_utf16, value_type, value_len, name); - if (!strcmp(name, "AspectRatioX")){ - int aspect_x = get_value(s->pb, value_type, 16); - if(stream_num < 128) - asf->dar[stream_num].num = aspect_x; - } else if(!strcmp(name, "AspectRatioY")){ - int aspect_y = get_value(s->pb, value_type, 16); - if(stream_num < 128) - asf->dar[stream_num].den = aspect_y; - } else { + if (!strcmp(name, "AspectRatioX") && stream_num < 128) { + dar_num[stream_num] = get_value(s->pb, value_type, 16); + if (dar_num[stream_num] > INT64_MAX) { + av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioX value: %"PRIu64"\n", dar_num[stream_num]); + return AVERROR(ENOTSUP); + } + } + else if (!strcmp(name, "AspectRatioY") && stream_num < 128) { + dar_den[stream_num] = get_value(s->pb, value_type, 16); + if (dar_den[stream_num] > INT64_MAX) { + av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioY value: %"PRIu64"\n", dar_den[stream_num]); + return AVERROR(ENOTSUP); + } + } else get_tag(s, name, value_type, value_len, 16); + + + if (stream_num < 128 && dar_num[stream_num] && dar_den[stream_num]) { + av_reduce(&asf->dar[stream_num].num, &asf->dar[stream_num].den, dar_num[stream_num], dar_den[stream_num], INT_MAX); + dar_num[stream_num] = 0; + dar_den[stream_num] = 0; } + av_freep(&name); }