From patchwork Fri Jan 7 16:51:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 33160 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp548555iog; Fri, 7 Jan 2022 08:52:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmSeUS8fOaE1bHBJZx/ijy6GsupMp0gW7u2rZGJx1iUQjUt0WLCPBNhZ00DQafyaBPFkWu X-Received: by 2002:a17:906:9756:: with SMTP id o22mr50026463ejy.324.1641574343998; Fri, 07 Jan 2022 08:52:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641574343; cv=none; d=google.com; s=arc-20160816; b=K7vnIduuDzS+xklKVu5xhWiIEs1sBHFIyAwXZP7ATPNNpqAY5eqHqFxYj9Us3IF6Rr zfWnLn1do29VBVJ4t3J3qrJVBeJKRzxvnCGAKf2YaA080iCfoTOBmp4i2bT3To1P+d1i 1sUUZOCXe4BYDeLQlQ4wubdJb4gjMA7m3RjMRHvBQXiNaBass0++4q6Hp4UjaHo/ci0o awhrjCxEwCcFY9IWiHiGrzeiGIKjXpr5VpU9ujJ1v3I2GEraelT3Xg4AKa25IxM/IGYN +RgRrh5HT7XcZhuBr7tzCwL8EbofV8CrLLtPje2wRqucq35EhYeNdbdfxXYc71EatwuN TCLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=Z/+yiP+bf9EaFZgwZS9KmY/CPhSb5eWTctsYuKJHhqg=; b=Qm4f1NUKMyCylj592rS6S01hPDk0l8WOVTKCDs9L+QY72AhAFDWoM9dBY/5f20Fb3v JMBDwitRkoMs7fuGyNEtqyvgJiQn19MyJXB5oc+oH3zcXsClsBU2OzGTcrv9aB0VWvpy V2tiW0fgEHALh2z2B3H8gYiRJauGkeWcPj8s5YVxou03n16PB9LbXmQW8yVMiDe6X87H +rd/rrpeDUGkX1JW9GUbMyR9hJLxT8VnL8nnZS9zol3VQ3I639qP7dbb88vN9Tf86+ZY CsbQEPBSkcTN4xcuH8qK55gwPZ82IRZFZkyq/oLyTVQzCz7F+zmQ2YMAIDLBHtlAilhc 5LpA== 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 cy12si2681994edb.558.2022.01.07.08.52.23; Fri, 07 Jan 2022 08:52:23 -0800 (PST) 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 DB08B68AAA0; Fri, 7 Jan 2022 18:52:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe02-1.mx.upcmail.net (vie01a-dmta-pe02-1.mx.upcmail.net [62.179.121.157]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CD37A68A255 for ; Fri, 7 Jan 2022 18:52:12 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1n5sTM-00FZvQ-0C for ffmpeg-devel@ffmpeg.org; Fri, 07 Jan 2022 17:52:12 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 5sSNnGKAOSgGF5sSNnhL4p; Fri, 07 Jan 2022 17:51:11 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=f8Q2+96M c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=NEAV23lmAAAA:8 a=BoEJPH_jbKWVwOerha4A:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 7 Jan 2022 17:51:11 +0100 Message-Id: <20220107165111.9929-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfO957POoNHIycN6kqNX/vKwuBpwrGUSlFDsm/NH4DfCbvRRJ9/e1JKs+c9XlN3XvVVdjus4MMud8xnLfhtOu8K0CcFSUUW5LbJoVDQKky1kjKX7BGD4/ 9IU9vLiqW/lQyhrTFYhODjeTu1Yn5GXsK1fQn3LY2Wnyazja7gJliGIe Subject: [FFmpeg-devel] [PATCH] avformat/rawvideodec: check packet size 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ImhCpjrHgkj7 Fixes: division by zero Fixes: integer overflow Fixes: 43347/clusterfuzz-testcase-minimized-ffmpeg_dem_V210X_fuzzer-5846911637127168 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/rawvideodec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c index 68547fc50ff..387c4ba80f5 100644 --- a/libavformat/rawvideodec.c +++ b/libavformat/rawvideodec.c @@ -42,6 +42,7 @@ static int rawvideo_read_header(AVFormatContext *ctx) enum AVPixelFormat pix_fmt; AVStream *st; int packet_size; + int ret; st = avformat_new_stream(ctx, NULL); if (!st) @@ -62,6 +63,10 @@ static int rawvideo_read_header(AVFormatContext *ctx) avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); + ret = av_image_check_size(s->width, s->height, 0, ctx); + if (ret < 0) + return ret; + st->codecpar->width = s->width; st->codecpar->height = s->height; @@ -100,6 +105,8 @@ static int rawvideo_read_header(AVFormatContext *ctx) if (packet_size < 0) return packet_size; } + if (packet_size == 0) + return AVERROR(EINVAL); st->codecpar->format = pix_fmt; ctx->packet_size = packet_size;