From patchwork Sun Jun 12 17:18:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36180 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97181pzb; Sun, 12 Jun 2022 10:19:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNGkaBfLYsIfAglM9EnvWTCubFZcvQXK/yDwUvQc4BWFO76nCL3d8wm4cFuHnbBv9ApWIu X-Received: by 2002:a17:907:a422:b0:705:e944:fd3e with SMTP id sg34-20020a170907a42200b00705e944fd3emr48489159ejc.309.1655054380440; Sun, 12 Jun 2022 10:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054380; cv=none; d=google.com; s=arc-20160816; b=rd63EZMrR06qaFrjrmql0ZNqJZL2Shmq/4qjJdA5+okQqJ0tqxxPW2cI/Xe8Bn5BU6 VGWjPqRB3eHQ4RAlKUvbntdbevHAzUYmhl6EYvqOv9XqmbrX7h10upkZ4mAk8B4Gesai Ki6rzZRgRROpcIKTYfFuO8CeILdhDkLKt4O39f6biQz0LIj1vQMe77t8oL/yFkeeojVu IbU9vYGD7V/AO0TC9jDH6lLk4SE4fx46txXeqgsO01mWfl9ExYVIQt6zYzLzzgu2GRAd 8k1PiPTUk6US2ohqvbG0t2PCmXAmKX3k6jmNTc92Ea6bSMUlU73l4DJzV/KumsSfhvOy 4qsw== 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:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=3Vo7g9b3pwZxUmpdGkhGhvRiFI2+oCHy1O3rYzuiUAU=; b=d8KNiD4MAAvjJ4M2trITyAXhXY1wOG/hAtw8VM8V/qKdtqoywrq/tw7oVGs1l4s3iD 5iATrQBbx8uo1h5xZezxGg8SrqGSv4Y0m4YmMgJ585v7pk5B4zKdd3aRBnttbginKdMB ph4nyiK2SKPzOghnBHEYzN8zDXfV3oz64bvymX5GC1kbEAabpX0d/Y7GNn2aRALK0hF9 KvO5DchCxh1EZudySGQMN+dAh/DvuaU2n+00YyVUPbYzJzGpCotiMHejb8eSVghXwAyd thNLAoe89BnobgJI3XFKrKTOfDoD3zdrQkoJYx9MtjI4VmEjV2VZPj7GH99zGrwwNAMu t3XQ== 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 cs16-20020a170906dc9000b006f3d2558d4bsi6212622ejc.496.2022.06.12.10.19.40; Sun, 12 Jun 2022 10:19:40 -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 86C6868B587; Sun, 12 Jun 2022 20:19:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5440568B4DF for ; Sun, 12 Jun 2022 20:19:05 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C37A9E70F7; Sun, 12 Jun 2022 19:19:05 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ndqPYwgSKvnA; Sun, 12 Jun 2022 19:19:04 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 616C3E6EA7; Sun, 12 Jun 2022 19:19:04 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:43 +0200 Message-Id: <20220612171845.8122-5-cus@passwd.hu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220612171845.8122-1-cus@passwd.hu> References: <20220612171845.8122-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7] avcodec/v210dec: add support for invalid paddings up to 16 bytes 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: xbckQqNFF+77 Fixes ticket #1528. Signed-off-by: Marton Balint --- libavcodec/v210dec.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c index 4268b5b748..ba48bb6fe4 100644 --- a/libavcodec/v210dec.c +++ b/libavcodec/v210dec.c @@ -126,6 +126,11 @@ static int v210_decode_slice(AVCodecContext *avctx, void *arg, int jobnr, int th return 0; } +static int v210_stride(int width, int align) { + int aligned_width = ((width + align - 1) / align) * align; + return aligned_width * 8 / 3; +} + static int decode_frame(AVCodecContext *avctx, AVFrame *pic, int *got_frame, AVPacket *avpkt) { @@ -137,20 +142,25 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic, if (s->custom_stride ) stride = s->custom_stride; else { - int aligned_width = ((avctx->width + 47) / 48) * 48; - stride = aligned_width * 8 / 3; + stride = v210_stride(avctx->width, 48); + if (avpkt->size < stride * avctx->height) { + int align; + for (align = 24; align >= 6; align >>= 1) { + int small_stride = v210_stride(avctx->width, align); + if (avpkt->size == small_stride * avctx->height) { + stride = small_stride; + if (!s->stride_warning_shown) + av_log(avctx, AV_LOG_WARNING, "Broken v210 with too small padding (%d byte) detected\n", align * 8 / 3); + s->stride_warning_shown = 1; + break; + } + } + } } if (avpkt->size < (int64_t)stride * avctx->height) { - if ((((avctx->width + 23) / 24) * 24 * 8) / 3 * avctx->height == avpkt->size) { - stride = avpkt->size / avctx->height; - if (!s->stride_warning_shown) - av_log(avctx, AV_LOG_WARNING, "Broken v210 with too small padding (64 byte) detected\n"); - s->stride_warning_shown = 1; - } else { - av_log(avctx, AV_LOG_ERROR, "packet too small\n"); - return AVERROR_INVALIDDATA; - } + av_log(avctx, AV_LOG_ERROR, "packet too small\n"); + return AVERROR_INVALIDDATA; } td.stride = stride; if ( avctx->codec_tag == MKTAG('C', '2', '1', '0')