From patchwork Fri May 4 17:43:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 8783 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp284090jad; Fri, 4 May 2018 10:45:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrGi0v2yJtne2am8GR3Az8gPFkGQnVbISOTmrpWVSo8TVwYcfwbhsvtAbe5y/euQnlTSTDg X-Received: by 2002:adf:8822:: with SMTP id d31-v6mr21312567wrd.18.1525455927110; Fri, 04 May 2018 10:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525455927; cv=none; d=google.com; s=arc-20160816; b=eBnn77lEoJ5+nLdafIQz83nBNKT+bWYdvq5H3VSUfri5v+LKPMpJv6i9TwH6gEdegM poNk0yR95Fk1eikkI3OhyO5GXYJdCPj6JEBuNM8FQwsn4kpBNmdALWKLm3IAA5vQ0zGp 65rnmsI7iwMPiWb2buhoDU+vZqDmANksol0EzcJbmzEmVYoL6keh5o3sGkL3rp1uSKPJ ujOgMNhuBffoBiU+DqAeGHMFmT+jTewhX0V+WUM+rdal1U1fhHAViJjEIxeoZMxdYLRC h16J/4BEz+xcgS103rRDnqBP0QQs5bQxMZiOBGUpv/c8QRg7BgcVFKkOB43nBH2D6E3P W36A== 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 :arc-authentication-results; bh=mIFFl9ikSm++cS3Kr66mjyeJv97EY6E8DJH61Xf361E=; b=CcC+JevG50nCir0706fglHNs5cVUY1Uu80Zq2JJASB4fFEXXI5A8k5Lj3/GvfmtryR FUUS95DIlLopvPAqQR/397BXZWkG+pVgn+DrIf/AyytQY5H6iswmiZx6oeCoCToqXTo4 iAwaqrvEehGv0ieY9C+o96eyIZ1lOrFbszE379Q4ynQFAEThGmeTZizdNkBymVcgvReZ gDa2o409Ee/8YrKf1jBMC9ue4/iNvgtEKxIuEfmIuRptAt6jVp2Ddl+Qv+XN9dwVqzfj JD7BueX8NzKYXcvIfS5H1AzTEeaFCjyY0mJsa6euCkayrfs2YZBPtyQg/wjAACubBbJK PK9A== 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 b50-v6si7434065wrb.301.2018.05.04.10.45.26; Fri, 04 May 2018 10:45:27 -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 4618F68A5BD; Fri, 4 May 2018 20:44:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-3.mx.upcmail.net (vie01a-dmta-pe03-3.mx.upcmail.net [62.179.121.162]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F3D768A4CB for ; Fri, 4 May 2018 20:44:36 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fEelZ-00062m-F3 for ffmpeg-devel@ffmpeg.org; Fri, 04 May 2018 19:45:09 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id iHl41x00h0S5wYM01Hl5pg; Fri, 04 May 2018 19:45:05 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 4 May 2018 19:43:45 +0200 Message-Id: <20180504174348.24364-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.0 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/g2meet: Change order of operations to avoid undefined behavior 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: signed integer overflow: 65280 * 196032 cannot be represented in type 'int' Fixes: 7279/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_G2M_fuzzer-5977332473921536 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/g2meet.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c index b409dae813..5edfb31560 100644 --- a/libavcodec/g2meet.c +++ b/libavcodec/g2meet.c @@ -1356,14 +1356,16 @@ static void g2m_paint_cursor(G2MContext *c, uint8_t *dst, int stride) } else { dst += x * 3; } - if (y < 0) { + + if (y < 0) h += y; + if (w < 0 || h < 0) + return; + if (y < 0) { cursor += -y * c->cursor_stride; } else { dst += y * stride; } - if (w < 0 || h < 0) - return; for (j = 0; j < h; j++) { for (i = 0; i < w; i++) {