From patchwork Sat Sep 26 10:27:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22600 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 CF14644A10F for ; Sat, 26 Sep 2020 13:30:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C74D6882F0; Sat, 26 Sep 2020 13:30:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 454E5688291 for ; Sat, 26 Sep 2020 13:29:55 +0300 (EEST) Received: by mail-wm1-f46.google.com with SMTP id l15so1071628wmh.1 for ; Sat, 26 Sep 2020 03:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bK0EC+GXViaFH33M/4LeX2M1YHVQCvF9jd2em1v4OGs=; b=PcNWnVcFoZ0rN3Kv8uwKwVbhSkzgYHdzQxmN+w1+4INW1xcNnuXgGnXx7sBMq81brs 4QXJIN8HWDpGVSsJOhueD/3Z58FUsbLnyzKdln87XeBuBZKT+gskejhpSEaDdDRORxo8 SreIqjvdq9In6zGpq25atU0OdBvJafB7PjdqBg1vnLmy/UMEgGzI2nlrvdywsQfP3/qw wDjzpGfFzfkkQVM9QhzqWbVemKYPyeT+BHauLeEAr2NrNY5BuIPQwQsVX/yclfSFtXCD AbFTsKXPmeBtHzDZhXyDfYFC6JEryk82Z8r4VnxmSWcVzOoXdAAHUL5MnVGPvQW4ANEX mAEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bK0EC+GXViaFH33M/4LeX2M1YHVQCvF9jd2em1v4OGs=; b=A0dySW70fwpOL1hMpXNuP7wOp+uD0RUNvY6hrssZeN7LI8IgeLfF2yCKhcQJ+is0Wu d1xgRAQlwi7/zRz8cMeOL8UQQEg9UCiWwY/b05OTc/dpRnmAbI861Kk3+LlIItO9pdHv v/l3VngkSLmJXNwKcFJvPcpUnovk4zprLbzPFjxoOu/pzR6r0bvDUKgRXVhb+SScnL17 XbgqLiTN0KucrZjFw3+wgBtuvjA2uO+mYjjGOaGXJUyU0840yIw3/5plDM8YLEQcuT80 v5PD7n1oQdL62JOQLjVPXgAJlAhWlc/+6I7QNDll+1YBzUEWthW2a8Q97Do892ZqsdOg kBag== X-Gm-Message-State: AOAM532I7S6zEwJAakaP7Sm4CLmDYjEMpn/zjurDduV6cTiu2Zpg4kuw /WBb6oBaCfn/9gaGJRhgeaunWEM2Ud8= X-Google-Smtp-Source: ABdhPJxKYT/sJXOL9XXLIrB3HWJjp5umZ5rsXWSKYZHQUkWkht7WxIyEgzF2XqOaAdrzBX3vgvyBZQ== X-Received: by 2002:a1c:f214:: with SMTP id s20mr2012440wmc.84.1601116194396; Sat, 26 Sep 2020 03:29:54 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:53 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:42 +0200 Message-Id: <20200926102804.228089-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/25] avcodec/magicyuv: Improve overread check when parsing Huffman tables 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index b56d3e9d32..d2f6a9b01e 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -394,8 +394,13 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) while (get_bits_left(gbit) >= 8) { int b = get_bits(gbit, 1); int x = get_bits(gbit, 7); - int l = get_bitsz(gbit, b * 8) + 1; + int l = 1; + if (b) { + if (get_bits_left(gbit) < 8) + break; + l += get_bits(gbit, 8); + } k = j + l; if (k > max || x == 0 || x > 32) { av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n");