From patchwork Sat Sep 17 21:15:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 37993 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp389545pzh; Sat, 17 Sep 2022 14:17:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4I1eyYgtOOExjWIQM3SYN8J67Tehdyjfcqu7MiSz3uU+jBtjruL9BjyOw7nlDIadtLxq0i X-Received: by 2002:a05:6402:3587:b0:451:30ca:c067 with SMTP id y7-20020a056402358700b0045130cac067mr9202609edc.195.1663449424402; Sat, 17 Sep 2022 14:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663449424; cv=none; d=google.com; s=arc-20160816; b=rs+Ddvhx/eLmz0wRQcXq7ZPslfrxTXv1bPboGJuRJi1GDQ8xHtGWHksm8wMmyslvvz oCwPjbtQ/BDMld4eCVO64bPIzFUz08PTHlHRcL47OPorQL0WzzdqdUPZbL1MJY3s/jyS aXONtM3Kia0peMb80YX68YpGUNd3u5EcOV3rzDXRq+A6TAvW507pfjvKv7vpcwi4OO41 z3HCrdBXN32ce3ytq1bV4Q1WVWsOoTEBy3Ulme2uoJ9oaAdZEPLv1Vz1jzVmDzZUb1uV TD+cpSWS6LHJhNc+GSNdIv2mK6frfpjuC8fOPHvW1f9QI7HbymGf3rTBaRuqPkasDj+i jdIw== 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=QOTchAE59+3DsZjUEcmcKX5i8i5WBImqEF8/eI1h2s4=; b=iaZhc6eofZePGGSJ4n9x23NK+bBWDCb7sZWlswcehIPGfV+1GH9viBdrqZlJKhGBpv fnmhcvfBFLaXt5H+1jm5HQtXkx1t4SnG4CnG8xRmAclEhEIvevZ75hvCd4zyHcpETk04 jGPGJlxn/XOYTC7o+4T9ziGTZNzN9qp7thU7QADt/i1pK3Fk/Wa9EvWQHXzEahrWdfQR hOxmzDF+fmlVv7LCMDZ/YG0pywEeKP7lttdZ18336z6GbJS+5mgYyPDUaPbmeo0GaExe gamrtUddQkomWXiU9rv1nyV91wdXq3V/x6yGePO1M0Kcw7Vpz4c4B2VoZbKF0Wmcey6U 4yAg== 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 t20-20020a170906179400b0072f1d8e7300si10893580eje.430.2022.09.17.14.17.04; Sat, 17 Sep 2022 14:17:04 -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 1CB3268BBD1; Sun, 18 Sep 2022 00:16:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at03-1.mx.upcmail.net (vie01a-dmta-at03-1.mx.upcmail.net [62.179.121.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CBD9268BB5A for ; Sun, 18 Sep 2022 00:16:00 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1oZfAO-00DrNV-CG for ffmpeg-devel@ffmpeg.org; Sat, 17 Sep 2022 23:16:00 +0200 Received: from ren-mail-psmtp-mg01. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id Zf9moPPmm8s8UZfAOoEt8M; Sat, 17 Sep 2022 23:16:00 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg01. with ESMTP id ZfAOoibLOOG5ZZfAOom24U; Sat, 17 Sep 2022 23:16:00 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.4 cv=KJo5sHJo c=1 sm=1 tr=0 ts=63263910 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=2pjwXNU-MM44mZu5czYA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 17 Sep 2022 23:15:56 +0200 Message-Id: <20220917211557.11547-8-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220917211557.11547-1-michael@niedermayer.cc> References: <20220917211557.11547-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfP7EFXbA4RImoSaLqAEXsIfCQQWF1iv1q3/3CzxnAESKXU1qaD7Zz26MjdpyfXW+Q+0ZdaQI6rEcZD3MHrBBCzJigvpKyM9qUgb7cQoSZ6MdB9+C6t31 Q96ZaI1NgZ5SeZN4TiT25daFGVT3ihJA8cBV5GllxyDHmNHYY0QoFsO+EXq7FmsqMAgyBZrF32pumg== Subject: [FFmpeg-devel] [PATCH 8/9] avformat/icodec: Check nb_pal 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: M5u4oRDGfTfY Fixes: signed integer overflow: 538976288 * 4 cannot be represented in type 'int' Fixes: 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_ICO_fuzzer-6690068904935424 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/icodec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/icodec.c b/libavformat/icodec.c index 290f658d0c0..85dab3bca0a 100644 --- a/libavformat/icodec.c +++ b/libavformat/icodec.c @@ -196,6 +196,9 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) AV_WL32(buf + 32, image->nb_pal); } + if (image->nb_pal > INT_MAX / 4 - 14 - 40) + return AVERROR_INVALIDDATA; + AV_WL32(buf - 4, 14 + 40 + image->nb_pal * 4); AV_WL32(buf + 8, AV_RL32(buf + 8) / 2); }