From patchwork Thu Sep 22 18:08:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 38153 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp499771pzh; Thu, 22 Sep 2022 11:09:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69kbxc7y+1ziA2aTcx88Sdo4Y2R1fl3GaskYCPYc3vL1j2WrHgz23GeZHhrvlIKKbCGbUf X-Received: by 2002:a17:906:9752:b0:780:1a57:9882 with SMTP id o18-20020a170906975200b007801a579882mr3928504ejy.318.1663870143547; Thu, 22 Sep 2022 11:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663870143; cv=none; d=google.com; s=arc-20160816; b=rB9fOIVuQTurrYJL7s75El7gvDw/eLOaSSKBXtSRQXEzeuhxVY44a1nk09j0BIGdZ1 HPaLRcaj7NVnZRF8nD+Z/2dVrKe5moSLI29GSfK4ZqR/euh+opdZUtB0LuyScI00iu2/ 12GJhN0/Z2/FpJ6uCZkT36GLMhX8Hc2h1usKMq3qTXb5nKrAwES666YNhbqVTxJ8BTjA D74UiVAJCWK1MJRqfIisjj+BNtzngMnAhBUnV7TU7Hhc6rd9loK0+hS2RrhM8TIv8r0Y Oj6C9mujzVeDUlsWhWyMPO6CDtpO47StgCJlZ5pePfQ5HtNIiExdIGRukuPp6F0JT78l 9M1Q== 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=Y5Q/DrmzQKedQtkoOu+ODxB0ycmfThBJw7mkbEfNjiQ=; b=ffjiQPfSQkDiTnZ4sjuqH2Z5FcKyv/feWkaVxgKoK81ldhEuJhZqo7uTP6VUxeRv1t Klh7PoiRd7i/RZNRX+kbQt2SIoSLRdK3kQmPoX3nxiPrE5VIwXIgkgmLqW81BwqHqZ14 DwKTZ28UiHK6olUCn/K5QyD9LmepndsVXaoePHUc7irmnvjU9ZuJbBlLuPxmKseqFGEB udVM2pe7pB8ETjirAL4sAvYXeV7Xet/PtJ+3Vo3suMQjhAUEBXIcq4V39j9PhbRCDi+B gqaZgRHJtzofJfJFLD/s26AjSyl8eU4F6FWbt9fNSENYzx3NJJOltrnwFMc+KchNtCcH m6Pw== 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 k26-20020a17090627da00b00780d18701f2si5276365ejc.176.2022.09.22.11.09.03; Thu, 22 Sep 2022 11:09:03 -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 882FC68BAA3; Thu, 22 Sep 2022 21:09:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at03-3.mx.upcmail.net (vie01a-dmta-at03-3.mx.upcmail.net [62.179.121.153]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A995E68B745 for ; Thu, 22 Sep 2022 21:08:54 +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 1obQd3-004DLa-9I for ffmpeg-devel@ffmpeg.org; Thu, 22 Sep 2022 20:08:53 +0200 Received: from ren-mail-psmtp-mg01. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id bQd2oTu7u8s8UbQd2oVNj7; Thu, 22 Sep 2022 20:08:53 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg01. with ESMTP id bQd2oMsWAOG5ZbQd2oukzn; Thu, 22 Sep 2022 20:08:52 +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=632ca4b4 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=0M_FlJwTtlK87it4aIcA:9 a=l4P9q1pZc1p6QgeJVkBh:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 22 Sep 2022 20:08:51 +0200 Message-Id: <20220922180852.20655-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfBCAGiwcYLelpk1yKpVKI3N3rqN96NxFL0bqa4OC9o8ywMs9agaWmu6X3dnPKL5jZm1gr8Yi9t29rpW/jV1Br1TYPulz37JZLxyeCDjxPa1G+ZfdqBQR UPiuj/VKWgj9R+oyIpw7AA/ZVkY9gB+jOB4zirT6p4EwwwVwuXl8LvdrfibX8Ib6azhYLeQwZ/098g== Subject: [FFmpeg-devel] [PATCH 1/2] avformat/vividas: 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: l7xRL4N23i9/ Fixes: signed integer overflow: 119760682 - -2084600173 cannot be represented in type 'int' Fixes: 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVIDAS_fuzzer-6745781167587328 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/vividas.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libavformat/vividas.c b/libavformat/vividas.c index e9954f73ed0..e8efe49a5c0 100644 --- a/libavformat/vividas.c +++ b/libavformat/vividas.c @@ -683,6 +683,7 @@ static int viv_read_packet(AVFormatContext *s, if (viv->sb_entries[viv->current_sb_entry].flag == 0) { uint64_t v_size = ffio_read_varlen(pb); + int last, last_start; if (!viv->num_audio) return AVERROR_INVALIDDATA; @@ -704,14 +705,22 @@ static int viv_read_packet(AVFormatContext *s, start = ffio_read_varlen(pb); pcm_bytes = ffio_read_varlen(pb); - if (i > 0 && start == 0) - break; + if (i > 0) { + if (start == 0) + break; + if (start < last || start - (unsigned)last > INT_MAX) + return AVERROR_INVALIDDATA; + } viv->n_audio_subpackets = i + 1; + last = viv->audio_subpackets[i].start = start; viv->audio_subpackets[i].pcm_bytes = pcm_bytes; } + last_start = viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb)); + if (last_start < last || last_start - (unsigned)last > INT_MAX) + return AVERROR_INVALIDDATA; viv->current_audio_subpacket = 0; } else { From patchwork Thu Sep 22 18:08:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 38154 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp500503pzh; Thu, 22 Sep 2022 11:10:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56xW+35uTj4FNK8jwnfitw/H0EwKguBlfsRuQHUOGnedjNp3tlLIR6e5A0KlbWHegWXGkT X-Received: by 2002:a17:906:fe09:b0:77a:52b3:da5d with SMTP id wy9-20020a170906fe0900b0077a52b3da5dmr3779867ejb.57.1663870201780; Thu, 22 Sep 2022 11:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663870201; cv=none; d=google.com; s=arc-20160816; b=pCKlcr0lSHHnwCm+07N2uWGtYvRYKxn2Ya4xnPtsqw3FeRP+axM1+cLTUnmFARrpG3 24Ve0OwQOQzLTYP0xinjYxXEuRHDGuhoSiSBMBoCC9e6oabDd1X/usFdzwba1L8HMH0C PkT1iInETNT+Nb9zZ/isJjvHT+DaN7+B6ROf3YCg5nZCzaXDjBux0qi0VMx5r+LLLkPY 9iuY5tDJYqwhnLksLj5qX+F1+y05SHzUBe0nzh0zAnJox/ZBrMIKxEQyaMqKDxMZCK0S fMmwFFMrQfpqkJHJZKmjdHK/Tjw3NRVZEaEpvh8Ip54PIyrYnnVfpHI5CsOq3ZBvXHid BusQ== 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=/xO0ripDYDWdtVLStXh69fKK16QSRgon6gZXkyqzQhY=; b=Tr/YYnmGCPb5xuKZsyceVQIgij+iR2YppzA9gNI0ujPu4Lt8XR0sJ6Ir6wi7VHG3nz 5/4MPKeHKBQXE7XtxZym44MnS7bwRKuKKm9VRu2jvhMOLzr2yc7OJe1K5FnSBBPxcxPV 1ivqVGAdDWyj1K1DKSL3DgdW1v0XztS1u4UivHmqy3tWU8aNelOG15GQA3wmK5kwP7F+ u6VZOCGl8DyB+r8XzPb7qRtACHcv3+wTz2ZdltrZ9pP5TAwL70S1JK8oXPWnhseCQc4n 7CNAdj/zc6PrNjNU0wfG6CDMQBdbJusShw/uJp7ZCTnhw9HzOiFEQq2oUBJWnAeQQKKg gzcQ== 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 du19-20020a17090772d300b0078281504806si551344ejc.162.2022.09.22.11.10.01; Thu, 22 Sep 2022 11:10:01 -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 93EEC68BB88; Thu, 22 Sep 2022 21:09:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at01-2.mx.upcmail.net (vie01a-dmta-at01-2.mx.upcmail.net [62.179.121.146]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 04D7C68B988 for ; Thu, 22 Sep 2022 21:09:53 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1obQe0-006QXH-1L for ffmpeg-devel@ffmpeg.org; Thu, 22 Sep 2022 20:09:52 +0200 Received: from ren-mail-psmtp-mg01. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id bQdyoTv9p8s8UbQe0oVNrH; Thu, 22 Sep 2022 20:09:52 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg01. with ESMTP id bQd2oMsWGOG5ZbQd2oukzp; Thu, 22 Sep 2022 20:08:52 +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=632ca4b4 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=4fAdcPnbGc7rnykZ210A:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 22 Sep 2022 20:08:52 +0200 Message-Id: <20220922180852.20655-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220922180852.20655-1-michael@niedermayer.cc> References: <20220922180852.20655-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfMv/d69kV2Ju17NudBahThVZflzAH9JJ/ItvgQsn+FLGeP54RZfFjdnMfo683vHuEAIBmfyDk4DQMuQryQg3TAO9ctb0wMzhG3m2p/FGOcP5eYasjAET n4q/jrh8gUzaldm8E19NWRnodqZsefrzw6u436Ra44S5gBOYBXy3Kp40/YqcJZyoRRKiAo5dDCub/A== Subject: [FFmpeg-devel] [PATCH 2/2] avformat/westwood_vqa: Check chunk 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: X8pRIyZzHtG0 the type is also changed to int as it is interpreted as int in av_get_packet() Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int' Fixes: 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_WSVQA_fuzzer-6593408795279360 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/westwood_vqa.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c index e3d2e2668c4..03b2d9e03c3 100644 --- a/libavformat/westwood_vqa.c +++ b/libavformat/westwood_vqa.c @@ -178,13 +178,15 @@ static int wsvqa_read_packet(AVFormatContext *s, int ret = -1; uint8_t preamble[VQA_PREAMBLE_SIZE]; uint32_t chunk_type; - uint32_t chunk_size; - int skip_byte; + int chunk_size; + unsigned skip_byte; while (avio_read(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) { chunk_type = AV_RB32(&preamble[0]); chunk_size = AV_RB32(&preamble[4]); + if (chunk_size < 0) + return AVERROR_INVALIDDATA; skip_byte = chunk_size & 0x01; if (chunk_type == VQFL_TAG) { @@ -193,9 +195,9 @@ static int wsvqa_read_packet(AVFormatContext *s, * so it can be combined with the next VQFR packet. This way each packet * includes a whole frame as expected. */ wsvqa->vqfl_chunk_pos = avio_tell(pb); - wsvqa->vqfl_chunk_size = (int)(chunk_size); - if (wsvqa->vqfl_chunk_size < 0 || wsvqa->vqfl_chunk_size > 3 * (1 << 20)) + if (chunk_size > 3 * (1 << 20)) return AVERROR_INVALIDDATA; + wsvqa->vqfl_chunk_size = chunk_size; /* We need a big seekback buffer because there can be SNxx, VIEW and ZBUF * chunks (<512 KiB total) in the stream before we read VQFR (<256 KiB) and * seek back here. */