From patchwork Thu Sep 8 18:42:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 482 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp980797vsd; Thu, 8 Sep 2016 11:46:49 -0700 (PDT) X-Received: by 10.28.50.3 with SMTP id y3mr33626wmy.23.1473360409155; Thu, 08 Sep 2016 11:46:49 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b75si10072985wma.30.2016.09.08.11.46.44; Thu, 08 Sep 2016 11:46:49 -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 25DDD689F88; Thu, 8 Sep 2016 21:46:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe04-2.mx.upcmail.net (vie01a-dmta-pe04-2.mx.upcmail.net [62.179.121.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 83738689E40 for ; Thu, 8 Sep 2016 21:46:26 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe04.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1bi4LL-0007My-QX for ffmpeg-devel@ffmpeg.org; Thu, 08 Sep 2016 20:46:35 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id h6ma1t00Q0S5wYM016mbUV; Thu, 08 Sep 2016 20:46:35 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 8 Sep 2016 20:42:59 +0200 Message-Id: <20160908184259.25081-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] avcodec/mlz: Check output chars before using it 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 hypothetical integer overflow Signed-off-by: Michael Niedermayer --- libavcodec/mlz.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libavcodec/mlz.c b/libavcodec/mlz.c index 039635d..a2d1b89 100644 --- a/libavcodec/mlz.c +++ b/libavcodec/mlz.c @@ -153,12 +153,27 @@ int ff_mlz_decompression(MLZ* mlz, GetBitContext* gb, int size, unsigned char *b mlz->bump_code = mlz->current_dic_index_max - 1; } else { if (string_code >= mlz->next_code) { - output_chars += decode_string(mlz, &buff[output_chars], last_string_code, &char_code, size - output_chars); - output_chars += decode_string(mlz, &buff[output_chars], char_code, &char_code, size - output_chars); + int ret = decode_string(mlz, &buff[output_chars], last_string_code, &char_code, size - output_chars); + if (ret < 0 || ret > size - output_chars) { + av_log(mlz->context, AV_LOG_ERROR, "output chars overflow\n"); + return output_chars; + } + output_chars += ret; + ret = decode_string(mlz, &buff[output_chars], char_code, &char_code, size - output_chars); + if (ret < 0 || ret > size - output_chars) { + av_log(mlz->context, AV_LOG_ERROR, "output chars overflow\n"); + return output_chars; + } + output_chars += ret; set_new_entry_dict(dict, mlz->next_code, last_string_code, char_code); mlz->next_code++; } else { - output_chars += decode_string(mlz, &buff[output_chars], string_code, &char_code, size - output_chars); + int ret = decode_string(mlz, &buff[output_chars], string_code, &char_code, size - output_chars); + if (ret < 0 || ret > size - output_chars) { + av_log(mlz->context, AV_LOG_ERROR, "output chars overflow\n"); + return output_chars; + } + output_chars += ret; if (output_chars <= size && !mlz->freeze_flag) { if (last_string_code != -1) { set_new_entry_dict(dict, mlz->next_code, last_string_code, char_code);