From patchwork Fri Feb 9 21:24:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 7537 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp1264013jai; Fri, 9 Feb 2018 13:25:21 -0800 (PST) X-Google-Smtp-Source: AH8x227aF/urdPZEtYhZ8tuGzCo7TfUvIEZWznwP1MUdgmaACOqAFjCWjYq5W9eeQCIoPvx01RNK X-Received: by 10.223.176.109 with SMTP id g42mr3420874wra.129.1518211521903; Fri, 09 Feb 2018 13:25:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518211521; cv=none; d=google.com; s=arc-20160816; b=mFy6im+Bp53i5B27+Tiwp0UDek5nPiCasp0tVFpt4S3aY+zW5YiduXJTHFprzBzhJF hEfOVUdCo8T/lIawYdK3urF4zcUvO0YlzOsKTb8siWsnj2zmabw45u3azVFyGxSpPjjb 3YQHQl4xj1kfccSf9MVR/rvQpBvD/mWJJt+DV/Gk/lJdEWZjPNNj4FgWKABV/K5Lj0YN MUBL+tnlGZ18l5G4Y68imiTCAjO/ISYbV+2X9Rr83eKXo1kesSwoTsF0pU1L3b1axy94 RLltBf6pWGAt7WrHEd+7n6uf1KqKn5GGEyXGcY1y9HX5udpqd1IoXOypT7EAF7/G3ny/ wu1Q== 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:arc-authentication-results; bh=nsIDWnD5WmTJKb6cVS0SgIR5Gjy7z766Y54qBwDVRKA=; b=GheNrEAHKgSlUk5TKTHOJwMddkLHyQUYPYrPOlUHM73IPMaL7uedgF1YIsoI32p5qr +a+hroGjawLTMxY6gPvkyKQKN/KIKBfWFPoXAUegon+SDdSLQhZzSwjIHhHSpQjuU3R1 BL5UDhddQzCzqzMbwIdO35POizUp5IAqVfwq+w0fL39Xw7sQ5o8Ce3WhJJLyUGTtMy+3 neOnoFfQV5Zthtgw5tYyUt3e9CASStMK4ep1Uu76H2/7SMivvsrqbwUEbqwebQ9bgMXy OwMZ2UrhR1vrwLcZA+kD3jlgAedgZ0zXluvvKTL9yWuWnTf8r70MUxofmJRZpnhqz+Gq y8Eg== 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 k130si2092953wmg.169.2018.02.09.13.25.21; Fri, 09 Feb 2018 13:25: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 AD9E868988D; Fri, 9 Feb 2018 23:25:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe01-1.mx.upcmail.net (vie01a-qmta-pe01-1.mx.upcmail.net [62.179.121.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2955680282 for ; Fri, 9 Feb 2018 23:25:04 +0200 (EET) Received: from [172.31.218.52] (helo=vie01a-dmta-pe08-1.mx.upcmail.net) by vie01a-pqmta-pe01.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1ekGAT-00011A-RD for ffmpeg-devel@ffmpeg.org; Fri, 09 Feb 2018 22:25:13 +0100 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1ekGAN-000752-SL for ffmpeg-devel@ffmpeg.org; Fri, 09 Feb 2018 22:25:07 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id 8lR11x04i0S5wYM01lR2ZB; Fri, 09 Feb 2018 22:25:02 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 9 Feb 2018 22:24:59 +0100 Message-Id: <20180209212459.30350-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180209212459.30350-1-michael@niedermayer.cc> References: <20180209212459.30350-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/utvideodec: Add several out of array read related checks 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: OV_decode_plane.avi Found-by: GwanYeong Kim Signed-off-by: Michael Niedermayer --- libavcodec/utvideodec.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index 1bcd14e74c..f0be2b231b 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -268,8 +268,12 @@ static int decode_plane(UtvideoContext *c, int plane_no, send = (height * (slice + 1) / c->slices) & cmask; dest = dst + sstart * stride; + if (3 * ((dst + send * stride - dest + 7)/8) > get_bits_left(&cbit)) + return AVERROR_INVALIDDATA; + for (p = dest; p < dst + send * stride; p += 8) { - int bits = get_bits_le(&cbit, 3); + int bits; + bits = get_bits_le(&cbit, 3); if (bits == 0) { *(uint64_t *) p = 0; @@ -277,6 +281,9 @@ static int decode_plane(UtvideoContext *c, int plane_no, uint32_t sub = 0x80 >> (8 - (bits + 1)), add; int k; + if ((bits + 1) * 8 > get_bits_left(&pbit)) + return AVERROR_INVALIDDATA; + for (k = 0; k < 8; k++) { p[k] = get_bits_le(&pbit, bits + 1); @@ -639,9 +646,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, for (j = 0; j < c->slices; j++) { c->packed_stream[i][j] = packed_stream; c->packed_stream_size[i][j] = bytestream2_get_le32(&pb); - left -= c->packed_stream_size[i][j]; - if (left < 0) + if (c->packed_stream_size[i][j] > left) return AVERROR_INVALIDDATA; + left -= c->packed_stream_size[i][j]; packed_stream += c->packed_stream_size[i][j]; } } @@ -652,9 +659,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, for (j = 0; j < c->slices; j++) { c->control_stream[i][j] = control_stream; c->control_stream_size[i][j] = bytestream2_get_le32(&pb); - left -= c->control_stream_size[i][j]; - if (left < 0) + if (c->control_stream_size[i][j] > left) return AVERROR_INVALIDDATA; + left -= c->control_stream_size[i][j]; control_stream += c->control_stream_size[i][j]; } }