From patchwork Mon Jan 22 21:25:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 7389 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.156.27 with SMTP id q27csp3457194jak; Mon, 22 Jan 2018 13:25:40 -0800 (PST) X-Google-Smtp-Source: AH8x225lBJvYWRTxeW4y8rdIjfgW2kA+aWl/s6V+m/weQuE2JhJQy0xAM9eFs6dmnaceT9XyLkIw X-Received: by 10.223.163.153 with SMTP id l25mr192362wrb.70.1516656340375; Mon, 22 Jan 2018 13:25:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516656340; cv=none; d=google.com; s=arc-20160816; b=e3sNB6lLxxqtxznA1Nzl6hdX0MXtWNCbkAWTOo84DGRVVCM8OogfjZ3Ie3mGYYZlzY E7H9VyHqESX0HMKF14hHaBfqgM2bEXOsRP48/hRbPAoWRR8tvn2EnBS029b2UM6bYO6i nuzDQcVHk/BQ2TmM3M+B89G8xaodlgJ7/0LOaNJivKc+uKnXqUp9GyMl+WhTHy++L+gn g5BEJZlSfBWfoJzo3sHCUfv0vlLOu/fpydeFnvtBHdo0fV2qD9TI42Cc4jnMqkPsoijt 1WTL4uEWX8QbXhN+rSGrliFNdjW485su53BIMVMoCopmAPg/XjEsiNya00guwn8fihwH Y04w== 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=hkCNU4XRcLgSsoHmE1uAssfDSrat8xISccJIYDtqQV8=; b=0MWwseVeBc/qjq20ZJRjgHB5ZUGSH9y6yWYAVahsVoqg0jlAyblN8U13EY3RoxVyUZ aZHr7sRngMX/5FN5L8pSKNGZhlnigMiWdipONVp2x1Z5ejJdxbClojaU0Q4k0Fou0RwP 2TuifyG+JM3u/1DbbB0mI+o/nv/fU7xyEHTTqAl+5+KGzyWCu2J8Mv0U58Gu2WuXoeC2 U78UURTvz+CZ4VBFMJoaF1SnN5spD8axtY+R5gk9in9BT7CHMmx6nf3bHpnCn4YQVjyq 3ILqi4rezEmLE6xjLobMQn6e1TKrwEoRcsi7EWrIbOv5C3Vcn/UcIWWi8u2zdwyVcvoV RPlw== 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 j11si5784666wmi.182.2018.01.22.13.25.39; Mon, 22 Jan 2018 13:25:40 -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 5906F68981C; Mon, 22 Jan 2018 23:25:36 +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 94CFA688312 for ; Mon, 22 Jan 2018 23:25:30 +0200 (EET) Received: from [172.31.218.54] (helo=vie01a-dmta-pe08-3.mx.upcmail.net) by vie01a-pqmta-pe01.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1edjau-0002bZ-6p for ffmpeg-devel@ffmpeg.org; Mon, 22 Jan 2018 22:25:32 +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 1edjao-0007ds-IQ for ffmpeg-devel@ffmpeg.org; Mon, 22 Jan 2018 22:25:26 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id 1ZRN1x00q0S5wYM01ZRPVl; Mon, 22 Jan 2018 22:25:23 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 22 Jan 2018 22:25:21 +0100 Message-Id: <20180122212521.20813-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.15.1 Subject: [FFmpeg-devel] [PATCH] avcodec/dxtory: Fix bits left 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: Timeout Fixes: 4863/clusterfuzz-testcase-6347354178322432 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/dxtory.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c index 6f8652ad49..e736cec8db 100644 --- a/libavcodec/dxtory.c +++ b/libavcodec/dxtory.c @@ -326,7 +326,7 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame *frame, int stride = frame->linesize[0]; uint8_t *dst = frame->data[0] + stride * line; - for (y = 0; y < left && get_bits_left(gb) > 16; y++) { + for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) { for (x = 0; x < width; x++) { b = decode_sym_565(gb, lru[0], 5); g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5); @@ -392,7 +392,7 @@ static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame *frame, int stride = frame->linesize[0]; uint8_t *dst = frame->data[0] + stride * line; - for (y = 0; y < left && get_bits_left(gb) > 16; y++) { + for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) { for (x = 0; x < width; x++) { dst[x * 3 + 0] = decode_sym(gb, lru[0]); dst[x * 3 + 1] = decode_sym(gb, lru[1]); @@ -437,7 +437,7 @@ static int dx2_decode_slice_410(GetBitContext *gb, AVFrame *frame, uint8_t *U = frame->data[1] + (ustride >> 2) * line; uint8_t *V = frame->data[2] + (vstride >> 2) * line; - for (y = 0; y < left - 3 && get_bits_left(gb) > 16; y += 4) { + for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) { for (x = 0; x < width; x += 4) { for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) @@ -481,7 +481,7 @@ static int dx2_decode_slice_420(GetBitContext *gb, AVFrame *frame, uint8_t *V = frame->data[2] + (vstride >> 1) * line; - for (y = 0; y < left - 1 && get_bits_left(gb) > 16; y += 2) { + for (y = 0; y < left - 1 && get_bits_left(gb) > 6 * width; y += 2) { for (x = 0; x < width; x += 2) { Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]); Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]); @@ -524,7 +524,7 @@ static int dx2_decode_slice_444(GetBitContext *gb, AVFrame *frame, uint8_t *U = frame->data[1] + ustride * line; uint8_t *V = frame->data[2] + vstride * line; - for (y = 0; y < left && get_bits_left(gb) > 16; y++) { + for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) { for (x = 0; x < width; x++) { Y[x] = decode_sym(gb, lru[0]); U[x] = decode_sym(gb, lru[1]) ^ 0x80;