From patchwork Sat Nov 12 23:43:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 39249 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1687912pzb; Sat, 12 Nov 2022 15:44:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf4xO9PyzNr0tnJPDgXz2+sqdNfHSaQfgldUfc3zSZPR9tBvhLRKTnbtRLs3CiNuArfZ/VJI X-Received: by 2002:a05:6402:1946:b0:461:5877:3741 with SMTP id f6-20020a056402194600b0046158773741mr6712409edz.64.1668296653802; Sat, 12 Nov 2022 15:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668296653; cv=none; d=google.com; s=arc-20160816; b=wKR7rj74KxxFs0WC414UgJX9e8+ROwUXd5mNK1SOxWhFiWEE+hfsqA1rNzghr+NXBG zUdj5no0xpXKRUMTNTI8rixjlhF+HnlHYiZbPjYNN4UqgbD/Us/d3qqQpGYkYnVMyp3q 3o9Nhr5sLSpwEzp5AhTrIW1cd6EdQdvDN+YvJG5otmdGXwvLzmf4AN1b81QkHO+Hi0kf pG8ll4VP1UrSWqNahM6n2KChWGQiTz9koyrv0fN8r4EylZ6Gm1F70YcylP7WuL/9dGuB OnftMevjq7af/gfVA6OJQA4TXlgXNheel8J6CWdwxWggcRdGchFo78ioOqR87Nml1EL3 jSZA== 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=W3MbS0OakdmTKj3R8mZVYFi/T+oUdH84rnWmk5grz/w=; b=HM+kr6n7Mz/mUu+GVyvQ7IXbcHVO+J/3ZCY1k8+dlWCEPA9wmI8C6gnJENKd1c572v A/7eXz11rM3Hwtg4iB2Y/8+UHf4m8AESlU3d+wl6Y0gm46l1USPmAd5KG3Ybk0Qt8A8v eLLWV0lryzureuObM37PSivaTnlYHg/5nqkJwKHv67+NdLb5NBNUEjjgZrTp+XtXUKgm EtTFakGIBczAwHW8PaouSeTFSJ1UVbpSACUmqGGx7viidQTEa93t7Fu/24IwxSWdoXD3 GI2oElM5MTc2h9A+f1WHbQSIUQKEdPY8mBB4fT45p9ROpRRYWwwXhZRlHWTty7yufbM2 kEnQ== 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 ne27-20020a1709077b9b00b007ae0e8f59a6si6217578ejc.821.2022.11.12.15.44.13; Sat, 12 Nov 2022 15:44:13 -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 A155B68BA32; Sun, 13 Nov 2022 01:44:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3086A68A241 for ; Sun, 13 Nov 2022 01:44:03 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 34A08FF805 for ; Sat, 12 Nov 2022 23:44:01 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 13 Nov 2022 00:43:59 +0100 Message-Id: <20221112234401.24158-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/lafdec: Check for EOF in header reading 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: 0QRiwD3Okt+t Fixes: OOM testcase Fixes: 51527/clusterfuzz-testcase-minimized-ffmpeg_dem_LAF_fuzzer-5453663505612800 OOM can still happen after this as an arbitrary sized block is allocated and read this would require a redesign or some limit on the sample rate. Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/lafdec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/lafdec.c b/libavformat/lafdec.c index 12b0d8540b..d02b479c4d 100644 --- a/libavformat/lafdec.c +++ b/libavformat/lafdec.c @@ -111,6 +111,9 @@ static int laf_read_header(AVFormatContext *ctx) sample_rate = avio_rl32(pb); duration = avio_rl64(pb) / st_count; + if (avio_feof(pb)) + return AVERROR_INVALIDDATA; + switch (quality) { case 0: codec_id = AV_CODEC_ID_PCM_U8; From patchwork Sat Nov 12 23:44:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 39250 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1687942pzb; Sat, 12 Nov 2022 15:44:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf50n575JB5iRQ2AWKp7Ek8Z8OCOfb4knFqSQQAq6M05ml2KedrvyknW0ibR/x2WdOGk5TMc X-Received: by 2002:a17:906:141b:b0:78d:5176:c4d2 with SMTP id p27-20020a170906141b00b0078d5176c4d2mr6150292ejc.532.1668296661640; Sat, 12 Nov 2022 15:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668296661; cv=none; d=google.com; s=arc-20160816; b=QA0xxmtdgEWw+ven6BXgnuUPexIdPRdJclNgJNCyTVysEuCDnba49XHCK3Mf2tGak1 tLXT9JgL3XI3dtmRZVhBbfI7iUCpNS+sX3umvqe+p7ksI0C8aOMU1ZP+m5ZEcQXeRCCT zWhi71UKHhVrQjjpC3Ju7XvNfi+rGOp0fP+hM2vDl+c3++Zn0Hp3wb53pkM3ydJA0KGG wkssrxOFgJ4VrATgcD8D8OCZ5vUQ1nlVKv59Bt7+hfi+FQXgRi3mMoggaBuGs8Zhfq19 lVgv4kCa+2v3hDHrs9bM7fV3XFBl649RHla4iL2sOCrZtHSBSDHyzmRn6/7C4jj2Uqf3 bpXA== 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:references:in-reply-to:message-id:date :to:from:delivered-to; bh=8JIzG2pwjHs9mxjMqnlfudqfRkrQKxD/JSCgQg/iSAY=; b=qG6jpKCctI2Ktmztzm3bQ+DkUBriODFyZYiq8R4A/FC/+nwXKCwKsYWwcfLS1/PEQd BjCd6DslLBTqmUYAC6AesKGtvubw1EEzaJ5UdvVq6ZzXBXKbYWyd7gWrwK81izkW3ryF D6rL3OG59KLK3zHfU/7QI/IRegoiaWKrf1HNeyPOUNwQy1vxgcCP3RyS7itRTS08cxWY uRRhjsgLqfQ7rqvSKkrtDGvlp4hIqLNNoM9Wj788wxhDoNH0bGO4rEdw7GrN1nGbBxck MIFyMkXay6tXub4CJ7dI9RE4DRnW8BkcyhKfsc/6OTtad+wvnrqOIUYAn/9oCMGjTTk1 qVpA== 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 z23-20020a17090665d700b007ad943d0608si4751386ejn.630.2022.11.12.15.44.21; Sat, 12 Nov 2022 15:44:21 -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 B590C68BA62; Sun, 13 Nov 2022 01:44:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F17368A241 for ; Sun, 13 Nov 2022 01:44:04 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 462F420004 for ; Sat, 12 Nov 2022 23:44:02 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 13 Nov 2022 00:44:00 +0100 Message-Id: <20221112234401.24158-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221112234401.24158-1-michael@niedermayer.cc> References: <20221112234401.24158-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/mjpegbdec: Check for AVDISCARD_ALL 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: i7Ifc2WXWG5b Fixes: Assertion failure Fixes: 51825/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MJPEGB_fuzzer-6393802688692224 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/mjpegbdec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c index 98c64b44ca..a82a95d70a 100644 --- a/libavcodec/mjpegbdec.c +++ b/libavcodec/mjpegbdec.c @@ -141,9 +141,10 @@ read_header: av_log(avctx, AV_LOG_WARNING, "no picture\n"); return buf_size; } - av_frame_move_ref(rframe, s->picture_ptr); s->got_picture = 0; + if (avctx->skip_frame == AVDISCARD_ALL) + return AVERROR(EAGAIN); *got_frame = 1; if (!s->lossless && avctx->debug & FF_DEBUG_QP) { From patchwork Sat Nov 12 23:44:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 39251 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1687960pzb; Sat, 12 Nov 2022 15:44:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Fm3jUGWwHYIHlo46G7HPEIu6dnciIfZGDCdMKV4jIdQCiSz6gcmAAxKrvlsO4rMIPtuBZ X-Received: by 2002:aa7:d3c1:0:b0:467:30ad:c4ca with SMTP id o1-20020aa7d3c1000000b0046730adc4camr6631062edr.285.1668296668913; Sat, 12 Nov 2022 15:44:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668296668; cv=none; d=google.com; s=arc-20160816; b=UmrHNJKIcLBuMEa4Xl7N4KtFFN/YEDNSOqlq765dMPVpMh6pFqJ+lvMMbqJioTvRHy lEUEbzkuulJIN8bomGdQK2wmclix08bEj+l8MZT4kL/jjXtNUybfdBObelYI+Uhie6r6 j3c7BEyNam6zt8x4/sWZ6skZ6xt0X+DawToLsII8HFdDKVecEhc7VXYZoJEumKOuWA6h TjnxRSv3rBZfll133piXT1iXPzMu8EqylA74mAaYoByel6avfsLtHMUWpEFt6A2nnbaQ OrgD0SGvZ167WgrcbVckVx6S8T5QMMWO7RQbZQbbqXN8nSSoT/o66paUpydxU2tU5UAx dU2Q== 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:references:in-reply-to:message-id:date :to:from:delivered-to; bh=fz7+siuBxu13bNto6Sm4yu7k11dgzm69ev34gRljokw=; b=a2m0lD+Xx9IfzjrMoPsO2pgVM9Wa6Jms9jFVD6m/uL2N8gPYjtYx6fGLaxKpXeMLCo rSpCfYWvQHQYjkzTeAv0A6x3yffSINbFBmsjTMNspguLCWs+UklrNyWW6w2uCqOdiyHB L2r9nUwf21t3GNf6snPWni5RA7zNo4eUbRQqz8kvvx7UGRaGFtbyKBJ7der+zL3HMVEM DaCaRW36CMxPF0ZiDMCyZJoYBRXQrbf1JjOUhHW+7FSsphmuVJE2IPiDsT1gQoCRoKMb qlc0qaQH9/ew9D3EmQ/MtUeryOCfn7uQ3ghd6QcWbFG6dUxweZn2yF3ohy4FTsKG257b D/eg== 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 gb14-20020a170907960e00b007ae4717bf08si6338497ejc.359.2022.11.12.15.44.28; Sat, 12 Nov 2022 15:44:28 -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 C32C668BA05; Sun, 13 Nov 2022 01:44:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2335A68BA05 for ; Sun, 13 Nov 2022 01:44:05 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 4D9941BF207 for ; Sat, 12 Nov 2022 23:44:04 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 13 Nov 2022 00:44:01 +0100 Message-Id: <20221112234401.24158-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221112234401.24158-1-michael@niedermayer.cc> References: <20221112234401.24158-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/3] avformat/mxfdec: Reduce overflows in essence_length computation 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: 6fI0ZHRN/x7J Fixes: signed integer overflow: -3741319169 - 9223372036823449370 cannot be represented in type 'long' Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-513039428681728 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mxfdec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index e6118e141d..42109cb43a 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -100,7 +100,7 @@ typedef struct MXFPartition { uint64_t previous_partition; int index_sid; int body_sid; - int64_t this_partition; + uint64_t this_partition; int64_t essence_offset; ///< absolute offset of essence int64_t essence_length; int32_t kag_size; @@ -3519,8 +3519,12 @@ static void mxf_compute_essence_containers(AVFormatContext *s) p->essence_offset = p->first_essence_klv.offset; /* essence container spans to the next partition */ - if (x < mxf->partitions_count - 1) - p->essence_length = mxf->partitions[x+1].this_partition - p->essence_offset; + if (x < mxf->partitions_count - 1) { + if (mxf->partitions[x+1].this_partition < p->essence_offset) { + p->essence_length = -1; + } else + p->essence_length = mxf->partitions[x+1].this_partition - p->essence_offset; + } if (p->essence_length < 0) { /* next ThisPartition < essence_offset */