From patchwork Tue Sep 3 23:03:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 14889 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 21F57448BF7 for ; Wed, 4 Sep 2019 02:03:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 06499687F09; Wed, 4 Sep 2019 02:03:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 446436804E8 for ; Wed, 4 Sep 2019 02:03:51 +0300 (EEST) Received: by mail-qt1-f194.google.com with SMTP id n7so22165194qtb.6 for ; Tue, 03 Sep 2019 16:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=3xxL+FmoWUKUjY2LaxWQR2JLx+Fp/M9EI5I1fI+Pjr0=; b=SEHIGJ29ip3jiqngtikuggO5nKtrW8+8dtvVLLgvwW+uxyPVcfPqM6bqIILuYnE8If sEujE5XSuLv/QWr+bJjUQLsGmwJmpbfuTC+fHnXXNN2S0qTmJTZqKpVo4kBx1DYwcPjE JSaSpcvXXGeujPzUaIYg4P4naGX81Rt/AvZt4ugP5PiNq49x2aw3kiBh40F6BQbQnT0m vozSpcHJ8TispX8N1UevccGWDSy3+SxOxZf43Eitz/mOyctOMDOqf/IQmT2B/2gNlRJQ IIAKY6ETe4GGM+4FK/SnnWCOQFWl9UTCq/KEdPNCO9xIMiZ0Rg9Ift4fF1OTkXD5NqR0 ec4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3xxL+FmoWUKUjY2LaxWQR2JLx+Fp/M9EI5I1fI+Pjr0=; b=bDXkQPTV0UIwzd915ooEd3D8g20ESJgUj073YzudkOxUKCvdSNPvwsoHSFyCGf8TG7 dfwMUnKGrdKjSDzEVWX4PJMoxmU0MwR4ytmRkdHRIHUoqjNH/4Zb+lfHjbDsHDc0VuIR xEoPBQvbYFp41hO2d7x8larF4w9m+xtuwfSeK8eTm3hdnS+96rtCKxkuiNPy/bPqw5dn svafmJxk+mrpw2yv24TWTZIotT9rmVxzqW5vvr8KyOE8fcXyhyMrbiEb1UqsFgYvbKtC yn25sNXbICE85PFezlbCZTENu5zU1PqCbdUDJC+FSa1hfSXCGXTC7vVNvyh79fMRLFt1 TkfQ== X-Gm-Message-State: APjAAAXuOfPHAbEQ/w3/g1FD65wfiCWpbfLfeLzmooAkA8vtScStIzTL vtl4T1UQe8NkwCDYCBe6yCP8ukX2 X-Google-Smtp-Source: APXvYqznUws/BG1qSN8s85CoT72EvOpxRWRgr2zv4DUeIl5RaJ+lOzaH1cGmIsVkoJqmmGjv28Kv/g== X-Received: by 2002:ac8:2b29:: with SMTP id 38mr20976418qtu.188.1567551829824; Tue, 03 Sep 2019 16:03:49 -0700 (PDT) Received: from localhost.localdomain ([191.83.220.27]) by smtp.gmail.com with ESMTPSA id u132sm428405qka.50.2019.09.03.16.03.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 16:03:49 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Sep 2019 20:03:00 -0300 Message-Id: <20190903230300.927-1-jamrial@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <8295984E-235F-4EAC-8344-09ADE71E724D@gmail.com> References: <8295984E-235F-4EAC-8344-09ADE71E724D@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2 v2] avformat/matroskadec: use av_fast_realloc to reallocate ebml list arrays 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Speeds up the process considerably. Fixes ticket #8109. Suggested-by: nevcairiel Suggested-by: cehoyos Signed-off-by: James Almer --- libavformat/matroskadec.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 439ee462a5..0f227eb33d 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -110,6 +110,7 @@ typedef const struct EbmlSyntax { typedef struct EbmlList { int nb_elem; + unsigned int alloc_elem_size; void *elem; } EbmlList; @@ -1236,8 +1237,14 @@ static int ebml_parse(MatroskaDemuxContext *matroska, data = (char *) data + syntax->data_offset; if (syntax->list_elem_size) { EbmlList *list = data; - void *newelem = av_realloc_array(list->elem, list->nb_elem + 1, - syntax->list_elem_size); + void *newelem; + + if ((unsigned)list->nb_elem + 1 >= UINT_MAX / syntax->list_elem_size) + return AVERROR(ENOMEM); + + newelem = av_fast_realloc(list->elem, + &list->alloc_elem_size, + (list->nb_elem + 1) * syntax->list_elem_size); if (!newelem) return AVERROR(ENOMEM); list->elem = newelem; @@ -1490,6 +1497,7 @@ static void ebml_free(EbmlSyntax *syntax, void *data) ebml_free(syntax[i].def.n, ptr); av_freep(&list->elem); list->nb_elem = 0; + list->alloc_elem_size = 0; } else ebml_free(syntax[i].def.n, data_off); default: