From patchwork Tue Feb 22 02:41:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 34436 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp3952594nkx; Mon, 21 Feb 2022 18:42:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0RhSeXOoDKbnP02lYr9hhMrINVhpR4U6PenpqCxNFtqUOEgBnMC5017iQWZrFE9fCWojo X-Received: by 2002:a17:906:360a:b0:6b9:1f8:9cdd with SMTP id q10-20020a170906360a00b006b901f89cddmr18091165ejb.461.1645497729467; Mon, 21 Feb 2022 18:42:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645497729; cv=none; d=google.com; s=arc-20160816; b=L8k+ro8rPwv1qTFwgCuZix1V74dA56J75Ntqy317CGURvm2sEMT25Um7v4HnGxOOFd f5+prtkULZAZZ+319S335JVwcYdC5PS04UvPwTh+9Eo1EuzEyvG/KgJYvE+GirbydmJe Uv8RY3cCDFm853xxCMf5gUyQJDdvLOY+xtdRVcssPgq4yGLIVDlGDcK9z3LakSqg3tcA EX25X0WKRmEDgCW2Ry2V9HKOAc08XEIp0OtskxrdH9qfLcceluE8AOjXjZX+RZu3bJar 2g7OtV8IoWQwcnMciahkQzpyM4tSdN4lEZKn00Ub2h82D89ZPMGp7CSDH4FnH6iiMZJX 9wDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=yvL1unIIF1UvhFTP5xV5XObMP93ttelzdf3VkVGo6t8=; b=P+8ivghsmYcsWxrizA022tO/zvRXRSekuMlU2I+IWxw2nYR36/1dgurtJ2UVPsUQic XjHy7o3SpdsvxlaemYDFzUj1yxeCgguaIEOyFwbk2lKYz4YZa5MV1tK04oz3wz8aAFKY h7X3A/4lsdNlQ2NhdW1nwf5/P1Rm28p8zNHhnCvMF0pV5BnAZcQjl96GgYGOrBJpl27t PS4EQm936f+9dodl+LUq8pRYVdc95KTVa/K21imeTYp69bnjb9ion4m9WcWEAeBWXAXQ IOOecb0jIPDNYlsyHVykDk4hkbYX073Hu6oA1iuQBC1mN+FGURcWroLAz3gkQiMGI+CK Ehig== 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 s1si13197944ejn.33.2022.02.21.18.42.08; Mon, 21 Feb 2022 18:42:09 -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 D21AF68AF73; Tue, 22 Feb 2022 04:42:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B859668A888 for ; Tue, 22 Feb 2022 04:41:57 +0200 (EET) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-03 (Coremail) with SMTP id rQCowACHj5twTRRicM30AA--.65304S2; Tue, 22 Feb 2022 10:41:53 +0800 (CST) From: Jiasheng Jiang To: ffmpeg-devel@ffmpeg.org, michael@niedermayer.cc, andreas.rheinhardt@outlook.com Date: Tue, 22 Feb 2022 10:41:51 +0800 Message-Id: <20220222024151.2469927-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: rQCowACHj5twTRRicM30AA--.65304S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tFy3Wr4rAr48ZryUtw1fJFb_yoW8KFW3p3 W7Cas5Jr93t3WfKFn7Ja4YqrWrW395J3WIg3y0qr9Fkrnxu3s8G348KFy0g3Wv9r4Fqw10 vF1Y9F15CF18AFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkj14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv 6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JUywZ7UUUUU= X-Originating-IP: [124.16.138.126] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Subject: [FFmpeg-devel] [PATCH v3] avformat/nutdec: Add check for avformat_new_stream X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Jiasheng Jiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 38FRlq5cmzc2 As the potential failure of the memory allocation, the avformat_new_stream() could return NULL pointer. Therefore, it should be better to check it and return error if fails. Also, the caller, nut_read_header(), needs to deal with the return value of the decode_main_header() and return error if memory allocation fails. And 'time_base_count' has already checked and it will return AVERROR_INVALIDDATA if fails, which is different from ENOMEM. Fixes: 619d8e2e58 ("updating nut demuxer to latest spec no muxing yet no index yet no seeking yet libnuts crcs dont match mine (didnt investigate yet) samplerate is stored wrong by libnut (demuxer has a workaround) code is not clean or beautifull yet, but i thought its better to commit early before someone unneccesarily wastes his time duplicating the work demuxer split from muxer") Signed-off-by: Jiasheng Jiang --- Changelog: v1 -> v2 * Change 1. Add the error handling for ENOMEM from decode_main_header() in nut_read_header(). * Change 2. Check for the 'time_base_count'. v2 -> v3 * Change 1. Remove the check for 'time_base_count'. * Change 2. Change the av_free to av_freep. --- libavformat/nutdec.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 0a8a700acf..32a4f6bbcb 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -351,8 +351,13 @@ static int decode_main_header(NUTContext *nut) ret = AVERROR(ENOMEM); goto fail; } - for (i = 0; i < stream_count; i++) - avformat_new_stream(s, NULL); + for (i = 0; i < stream_count; i++) { + if (!avformat_new_stream(s, NULL)) { + av_freep(nut->stream); + ret = AVERROR(ENOMEM); + goto fail; + } + } return 0; fail: @@ -800,19 +805,23 @@ static int nut_read_header(AVFormatContext *s) NUTContext *nut = s->priv_data; AVIOContext *bc = s->pb; int64_t pos; - int initialized_stream_count; + int initialized_stream_count, ret; nut->avf = s; /* main header */ pos = 0; + ret = 0; do { + if (ret == AVERROR(ENOMEM)) + return ret; + pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1; if (pos < 0 + 1) { av_log(s, AV_LOG_ERROR, "No main startcode found.\n"); return AVERROR_INVALIDDATA; } - } while (decode_main_header(nut) < 0); + } while ((ret = decode_main_header(nut)) < 0); /* stream headers */ pos = 0;