From patchwork Sat Jan 21 02:19:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 2267 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp338002vsb; Fri, 20 Jan 2017 18:19:39 -0800 (PST) X-Received: by 10.223.148.230 with SMTP id 93mr12570029wrr.13.1484965179666; Fri, 20 Jan 2017 18:19:39 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r24si10017530wrr.241.2017.01.20.18.19.38; Fri, 20 Jan 2017 18:19:39 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 93CAA68A7FD; Sat, 21 Jan 2017 04:19:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f41.google.com (mail-it0-f41.google.com [209.85.214.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CBE5468A3C5 for ; Sat, 21 Jan 2017 04:19:18 +0200 (EET) Received: by mail-it0-f41.google.com with SMTP id c7so33238816itd.1 for ; Fri, 20 Jan 2017 18:19:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=bXPCmbeM+GQnj5rh5JAJt+u9QTztANo9kGUW2Hn+W/4=; b=VuJi+YHWX6tpNUUEBmVblwbiDZhd7DHIH4wjNKRnY8QvRL1xQ70x16thaYNbBD7zwP NvIPrWH1rAojNvpM8pvGigPlZMGqfOGs/vFyVIK8VGFFt0oXPS0jy/nnzNUaV4lDdJAf 4V6LfZw11EUuH6USWOVW+0Vvj4uFEQkXF0abWCuK0aJzgb95hSUiB48JNLUzE8n79RgK Ho1Z3XOhD9/QE0B7qxhnTiEy7eKQ/5/I98A5oIhN7E3pP1Z52+3Jj3Y2IrSpos8d6E92 eC6vGv7bbsXOBgSTJGC+08Mi7ufcZg6xs8Nv/W72UxoND4NYc0kEPsftXligfQHoV8rk VW2Q== 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; bh=bXPCmbeM+GQnj5rh5JAJt+u9QTztANo9kGUW2Hn+W/4=; b=TZ5UZGSqvpvwa35BDG0s5Iem0/zh/TqF0DM5KoSIkk/JhZ7awXff5KFqOY3ELzH9MF Ljy/CEGZOAwmVToTvPE/hFwJBJVNL3fMEHOjzAhrjTNcm+g6bMiuGHZMGrHnAcLrYjY8 6TJKEpEB/D7ZEtwbMRR2yvr9pJWme+IiWLlfLdBKbjLeBPRRFEOJlj1ZDfE/RZu9PbZb UBWcVIgYomfp8fZBsV+nGHBEJejMQk1hDAGeQXAgXKbgbWvYvLOmGUeQVCkDgB7H3wL0 2KP9Sjtn9nBSs0RWAl26b8xHwLVay5OOhLfjA4c7nknlmZ56a96mdWfMdz09EySHxpw4 T01w== X-Gm-Message-State: AIkVDXLt1G7nHMGm/Bt9WcRQbrpe6PWDR2K3Lt2mYwQxjRMfKWHhKkuaTQ9FPZqkp2cw+A== X-Received: by 10.36.240.11 with SMTP id s11mr6716643ith.16.1484965168626; Fri, 20 Jan 2017 18:19:28 -0800 (PST) Received: from Rodgers-MacBook-Pro.local.net (c-73-110-121-59.hsd1.il.comcast.net. [73.110.121.59]) by smtp.gmail.com with ESMTPSA id e192sm4883056iof.26.2017.01.20.18.19.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Jan 2017 18:19:27 -0800 (PST) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Jan 2017 20:19:24 -0600 Message-Id: <20170121021924.51394-1-rodger.combs@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] lavf/segment: fix crash when failing to open segment list 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This happens because segment_end() returns an error, so seg_write_packet never proceeds to segment_start(), and seg->avf->pb is never re-set, so we crash with a null pb when av_write_trailer flushes the packet queue. This doesn't seem to be clearly recoverable, so I'm just failing more gracefully. Repro: ffmpeg -i input.ts -f segment -c copy -segment_list /noaxx.m3u8 test-%05d.ts (assuming you don't have write access to /) --- libavformat/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/segment.c b/libavformat/segment.c index 9b3dc178eb..9d471483b3 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -354,6 +354,9 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) int i; int err; + if (!oc || !oc->pb) + return AVERROR(EINVAL); + av_write_frame(oc, NULL); /* Flush any buffered data (fragmented mp4) */ if (write_trailer) ret = av_write_trailer(oc); @@ -850,7 +853,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) int64_t usecs; int64_t wrapped_val; - if (!seg->avf) + if (!seg->avf || !seg->avf->pb) return AVERROR(EINVAL); calc_times: