From patchwork Sun Apr 21 09:05:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 12852 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 233704484D6 for ; Sun, 21 Apr 2019 12:08:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 122B068A8F1; Sun, 21 Apr 2019 12:08:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-3.mx.upcmail.net (vie01a-dmta-pe06-3.mx.upcmail.net [84.116.36.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F311868A7F4 for ; Sun, 21 Apr 2019 12:08:01 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.91) (envelope-from ) id 1hI8S9-0006Vc-1n for ffmpeg-devel@ffmpeg.org; Sun, 21 Apr 2019 11:08:01 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id I8RAhsvKl5D5NI8RAhDtPH; Sun, 21 Apr 2019 11:07:00 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=bu8y+3Si c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=l3AyKO-iX-Msjnf_kJ8A:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=pHzHmUro8NiASowvMSCR:22 a=nt3jZW36AmriUCFCBwmW:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 21 Apr 2019 11:05:17 +0200 Message-Id: <20190421090519.27335-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfO/X5LTIP779zriOb8bZPWUHZRqbnovhHjIbp3PqMjYzp9KJnGY2oQp1PKss3cJx9PCCyPzn1kc+8KmvFEkSsi3ahzmrdiiJxl8KAa8cXrfQB/257nW+ OJWk0YMtmrkdYiPuLLaQaw27izaq6HPa94xUlzPjBrDkmo31TRUwA/O4 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/agm: Do not crash on invalid codes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" I do not know if such vlc trees are allowed in agm, I have no specification So i do not know if these should be treated as error, or not. But the code does contain a check for idx < 0 already ... untested due to lack of valid samples using this codepath Fixes: Stack-buffer-overflow in get_tree_codes Fixes: 14189/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5745747003179008 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/agm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/agm.c b/libavcodec/agm.c index f5fd5d065e..f3d81bf163 100644 --- a/libavcodec/agm.c +++ b/libavcodec/agm.c @@ -913,7 +913,7 @@ static void get_tree_codes(uint32_t *codes, Node *nodes, int idx, uint32_t pfx, { if (idx < 256 && idx >= 0) { codes[idx] = pfx; - } else { + } else if (idx >= 0) { get_tree_codes(codes, nodes, nodes[idx].child[0], pfx + (0 << bitpos), bitpos + 1); get_tree_codes(codes, nodes, nodes[idx].child[1], pfx + (1 << bitpos), bitpos + 1); }