From patchwork Thu May 7 22:55:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19548 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 1DD5A44A6EB for ; Fri, 8 May 2020 01:55:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0179A68A9F3; Fri, 8 May 2020 01:55:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 46890689C9E for ; Fri, 8 May 2020 01:55:13 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id u127so8673592wmg.1 for ; Thu, 07 May 2020 15:55:13 -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:mime-version :content-transfer-encoding; bh=52DmQuGnmvC2mLXloFGWWWJhqZI/I9ymYfZPIzNfpLo=; b=MYlDQZlfFeQdYGnF5wTuOb4q/7iPVy3kYgkm3zhsMc4iYwjxdU3TnmUtrna6+2ybKC K0iTHzv8J0cXonrEcVssI9yOpmv36bUdRocmK0dnNd+aQZB5DN702FjvKlEHaJPnsr0m VsaWb83LG2UARK42hPbWWLBu1uukiU7ySSO6Zk5q+AA5yUAXQfWksmmi4pFbgcUZbUor oa+n0mXWAvaNf1Bq2e9Hys9+zAOUAGxHQnXey+5opfwI6xwis+ZTvx0YwcPTj0LztJ7c N1LxZUK8SUymHzj+FKGNtAh+5E59VZFUMSBZrCUSsHYMvfkxU/cmGVm6hg6mToA5Bfg8 +DDg== 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:mime-version :content-transfer-encoding; bh=52DmQuGnmvC2mLXloFGWWWJhqZI/I9ymYfZPIzNfpLo=; b=lnDaZ6brTySoKGRqwIOES+GZhBDlDRtBlHnqCb29neAD8zhMs20o+zOSVxeZAN5BEK C7jRLzz7/TJU4ig8cRDfDqnP5b3NXqOKHishca+y7lgGUOfVjDdynS8wwHPnLl6Fp2BV YupzC4S6EB+5dIHOTw/X1zF1XONmf6+7aQh6+mxeB8XNiiADYpOnGxSGzWgyBbYbUtkR lLIeeyqWVQYW/U+aPycfmHprwxz855xgMpNwEAYNcrDbivNYOjfsCFej7LwSYwUGd8yK PzWBcpxiBngM1p13fbSM4s9q43b+aTRUWkoBDNVIN1dJdlxTofr5xLhsHYeXimYldCUt GbvQ== X-Gm-Message-State: AGi0PuZU7AGU6l/9fyd3xm91u8+aWU0ADM/4T7ZG/5oocqxrMMRI1Z7p 7P9LY99HyKGV+8BURY+mtU9de29n X-Google-Smtp-Source: APiQypJ6pnx3Qm2/cdB/n0lA2g5h4MwPwsHs3lnkNhU0YmO7khC2eQ8GcclNs5pcl/nXrGuWavyM5g== X-Received: by 2002:a7b:c7d2:: with SMTP id z18mr13445695wmk.72.1588892112695; Thu, 07 May 2020 15:55:12 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id q8sm9997657wmg.22.2020.05.07.15.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 15:55:12 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 May 2020 00:55:00 +0200 Message-Id: <20200507225500.26860-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mux: Check pkt->stream_index 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit fixes two recent regressions both of which are about using pkt->stream_index as index in an AVFormatContext's streams array before actually comparing the value with the count of streams in said array. 96e5e6abb9851d7a26ba21703955d5826ac857c0 did this in prepare_input_packet() and 64063512227c4c87a7d16a1076481dc6baf19841 did likewise in write_packets_common(). Signed-off-by: Andreas Rheinhardt --- The same error in the same file applied on the same day by two different people. How unlikely. libavformat/mux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 41659b19c9..f2de73af9b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -761,12 +761,13 @@ static int check_packet(AVFormatContext *s, AVPacket *pkt) static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt) { + AVStream *st; int ret; - AVStream *st = s->streams[pkt->stream_index]; ret = check_packet(s, pkt); if (ret < 0) return ret; + st = s->streams[pkt->stream_index]; #if !FF_API_COMPUTE_PKT_FIELDS2 || !FF_API_LAVF_AVCTX /* sanitize the timestamps */ @@ -1176,10 +1177,11 @@ static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket *p static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleaved) { - AVStream *st = s->streams[pkt->stream_index]; + AVStream *st; int ret = prepare_input_packet(s, pkt); if (ret < 0) return ret; + st = s->streams[pkt->stream_index]; ret = check_bitstream(s, st, pkt); if (ret < 0)