From patchwork Tue Dec 3 17:09:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16565 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 AFC3244ACC9 for ; Tue, 3 Dec 2019 19:09:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97B1E68B4B2; Tue, 3 Dec 2019 19:09:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BECB268B4AF for ; Tue, 3 Dec 2019 19:09:34 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id y17so4632252wrh.5 for ; Tue, 03 Dec 2019 09:09:34 -0800 (PST) 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=uly6x9oikazKW3l9gAAa2oos2Db7vQBx2AxHtMLACVQ=; b=VEXGP1ZMXgiZHxgG2ilDCHaDwwbZBgcMj/fQGoxqovBW2vx5OD+GYAmKYdbYMqFI/L WuAoCWukvt3HCG0ySG5Tduxb4/OIW0LFhKPeImwEYeq8sqkj9ejx/t4+Eeyyzereh9AH R748X7lPVUT+XYMBQ1blwsolLNOAT/ilWaFK2wqKk28nxNJgNo7oxWCjm56mD6csl8FN 3QrTyGpZ/IvLsGrTrtNASd7qj8IwJR/3vENuTqzqgdamqrdPw3MrfLMGy1G+HkUCAWgv 95ZHqxVoLL5D5Qez7siFb3OBohwNdalhAFnLMdAGlIuWtKlNhYnbgNWNi4fp0fmGfyMY 5kyg== 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=uly6x9oikazKW3l9gAAa2oos2Db7vQBx2AxHtMLACVQ=; b=LjSvDZsxsU7gxQj3bt2eJg9jfXIfqQYh5Rmx+3dTlsfFhW1w9PRJjPezNTvDx27aek WNsHBpcMASqdDmkD0e6gi1fUtua4cm1HsIqV6SvUzbLQhwL9s8VVgUyICZv7Ma7baT46 5nsGe2aGodZtDulX3XL6zEj5IbWst41HsVoVuGub6J3/DKOLjyjVQuA5eDVmwoS/QoRd 5Fwdm7cyOZoYai7DynL7OZf60pwA6Ao+lpN9e2kZLfFYosVD/iQ2By179n7p7MxDtVG9 qWomzPnxY6YW2q16KjyqM4ADdDn1eKol1BZ5fhqveZuL5s3DQ6zZ3oX+oXa42PV9Cv5x Purg== X-Gm-Message-State: APjAAAUXcoJaaoHQFn3JlnkIau1FNiMwuQC7dor5ADY6sEdSrXANcRj+ +nimBhk88ldmr75Qo81qQtN4Q7gT X-Google-Smtp-Source: APXvYqx9bUJAq1lXWg1jp3tXUaLsmksQnEqBMDWyaL3SrSymvtCXgyVTIVohWZPa3WuMpgZoG1DYoA== X-Received: by 2002:adf:83c7:: with SMTP id 65mr6074185wre.368.1575392974131; Tue, 03 Dec 2019 09:09:34 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id x21sm3513630wmj.44.2019.12.03.09.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2019 09:09:33 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Dec 2019 18:09:06 +0100 Message-Id: <20191203170910.5310-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203170910.5310-1-andreas.rheinhardt@gmail.com> References: <20191203170910.5310-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] avformat/matroskadec: Avoid allocating array for lace sizes 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" The maximal number of frames in a lace can be 256; hence one has a not excessive upper bound on the size of an array that can hold the sizes of all the frames in a lace. Yet up until now, said array has been dynamically allocated. This has been changed. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 32bd6b8446..2f289a90b3 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2990,19 +2990,14 @@ static void matroska_clear_queue(MatroskaDemuxContext *matroska) static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, int *buf_size, int type, - uint32_t **lace_buf, int *laces) + uint32_t lace_size[256], int *laces) { int res = 0, n, size = *buf_size; uint8_t *data = *buf; - uint32_t *lace_size; if (!type) { *laces = 1; - *lace_buf = av_malloc(sizeof(**lace_buf)); - if (!*lace_buf) - return AVERROR(ENOMEM); - - *lace_buf[0] = size; + lace_size[0] = size; return 0; } @@ -3010,9 +3005,6 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, *laces = *data + 1; data += 1; size -= 1; - lace_size = av_malloc_array(*laces, sizeof(*lace_size)); - if (!lace_size) - return AVERROR(ENOMEM); switch (type) { case 0x1: /* Xiph lacing */ @@ -3093,7 +3085,6 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, } *buf = data; - *lace_buf = lace_size; *buf_size = size; return res; @@ -3531,7 +3522,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf int res = 0; AVStream *st; int16_t block_time; - uint32_t *lace_size = NULL; + uint32_t lace_size[256]; int n, flags, laces = 0; uint64_t num; int trust_default_duration = 1; @@ -3590,10 +3581,9 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf } res = matroska_parse_laces(matroska, &data, &size, (flags & 0x06) >> 1, - &lace_size, &laces); - - if (res) - goto end; + lace_size, &laces); + if (res < 0) + return res; if (track->audio.samplerate == 8000) { // If this is needed for more codecs, then add them here @@ -3627,7 +3617,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf lace_size[n], timecode, pos); if (res) - goto end; + return res; } else if (st->codecpar->codec_id == AV_CODEC_ID_WEBVTT) { res = matroska_parse_webvtt(matroska, track, st, @@ -3635,7 +3625,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf timecode, lace_duration, pos); if (res) - goto end; + return res; } else { res = matroska_parse_frame(matroska, track, st, buf, data, lace_size[n], timecode, lace_duration, pos, @@ -3643,7 +3633,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf additional, additional_id, additional_size, discard_padding); if (res) - goto end; + return res; } if (timecode != AV_NOPTS_VALUE) @@ -3652,9 +3642,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf size -= lace_size[n]; } -end: - av_free(lace_size); - return res; + return 0; } static int matroska_parse_cluster(MatroskaDemuxContext *matroska)