From patchwork Thu Nov 24 17:59:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Sarnie X-Patchwork-Id: 39406 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp4732701pzb; Thu, 24 Nov 2022 09:59:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf56QYQHTwFWc6qnIPdkTyy88QqNEJnqPxY5XkGK+HBntHxQ0PTjbNOxeX/HRKV1xmaSuxzt X-Received: by 2002:a17:907:a80d:b0:7ba:298d:f34 with SMTP id vo13-20020a170907a80d00b007ba298d0f34mr6733168ejc.150.1669312788893; Thu, 24 Nov 2022 09:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669312788; cv=none; d=google.com; s=arc-20160816; b=mjhXwchTRXX4AqZ6zg8R8Rw54ZmHqhbObIi/kPurMDO2hQi1bPCjGsfzvd5Js23g+Q xD6nV5bP0uMcn7Pw1RcBrQ/jqyywJAcN9vmfMMUPWZQGA746+9We7ZsBDltyRFXWeg4R DLBXXpxKzArz3t14zLUCtDwJi4B8RUM0HnU+7SRlTcqTM+OV63fKkXmcsI8SsrpFAFwj 0xan6jvcGpG88zzSGkaAFBEeef5eIab27Q/C7Uv1+JSTr+KJtRjTWlgC0OhhAQKkD43O CYhORtJ/IfguV3yoGkWzmGtyG3m+wZ+ZcGkBGqzWr7lcszDeU4/KbfS2DgqlC85A491E WB/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:to:from:user-agent:mime-version :date:message-id:delivered-to; bh=6/8rSdOFx1HCq2vSJA+YjN+yKap7lBa/TN+EEQyLn1s=; b=rLfDPLTrd5GuE44/mcBi5MpS/JpDaJGOGI5dmItH5FEte3mXCV9Kmxmx0liXx/z2zh TRM9NSMY9F1NCgioqogUqS8NgZB7uZOIQa4mrEk/LYZgGJv0uJQYNaBV5ytg4717icMV IHNC3ey28ptcds/w1S1FLzPXWcU1/fzqz+dYh3knUU7togW/EPfK8+Qgv1f8z3LL/ch7 OXuXWivqoUOpRBWDNhVAVdJxqmuAQL/QNgUacwYp9cwnGRuX1CSS8xCj5l8gUhWI8szc SV3gKi991DqrkMsWBr+1dPi81h+FoZLKwax4fZmSM9wF2G0ylnk/dwR9YHORg8cY7mQy mm8A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j8-20020a50ed08000000b0046a02740cf8si1321502eds.109.2022.11.24.09.59.43; Thu, 24 Nov 2022 09:59:48 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9438568B574; Thu, 24 Nov 2022 19:59:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A51F168A33E for ; Thu, 24 Nov 2022 19:59:33 +0200 (EET) Message-ID: Date: Thu, 24 Nov 2022 12:59:27 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 From: Nick Sarnie To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] avformat/file: Fix handing of file URIs 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WxWrtHfIOtqN The current URI handling only removes the file: prefix, but we also need to consider the case of percent encoding. Percent encoding can happen with non-ASCII characters in the path. I hit this through mpv with vobsub subtitles when dragging subtitles onto the player using the mouse. Vobsub uses two files: an .idx file and a .sub file. mpv decodes the file path for direct inputs to mpv (the .idx file here), so that's why mpv works for most things today. When passed the .idx file from a mouse-drag, mpv calls the FFmpeg mpeg demuxer which then tries to find the corresponding .sub file in vobsub_read_header. However, mpv does not decode the path for the vobsub track name, which FFmpeg uses to find the sub file, so open() was receiving the path with "file:" removed but still had the percent encoding, so it obviously failed. I have a similar patch for mpv to make mpv decode the vobsub sub file name before passing to FFmpeg as well, but I have received feedback from multiple mpv developers that this is also a FFmpeg issue, so hopefully we can fix it in both places. Signed-off-by: Nick Sarnie --- libavformat/file.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) const char *filename = h->filename; av_strstart(filename, "file:", &filename); - + filename = ff_urldecode(filename, 0); + if(!filename) + return AVERROR(ENOMEM); { #if HAVE_ACCESS && defined(R_OK) if (access(filename, F_OK) < 0) @@ -174,7 +177,9 @@ static int file_delete(URLContext *h) int ret; const char *filename = h->filename; av_strstart(filename, "file:", &filename); - + filename = ff_urldecode(filename, 0); + if(!filename) + return AVERROR(ENOMEM); ret = rmdir(filename); if (ret < 0 && (errno == ENOTDIR # ifdef _WIN32 @@ -196,7 +201,13 @@ static int file_move(URLContext *h_src, URLContext *h_dst) const char *filename_src = h_src->filename; const char *filename_dst = h_dst->filename; av_strstart(filename_src, "file:", &filename_src); + filename_src = ff_urldecode(filename_src, 0); + if(!filename_src) + return AVERROR(ENOMEM); av_strstart(filename_dst, "file:", &filename_dst); + filename_dst = ff_urldecode(filename_dst, 0); + if(!filename_dst) + return AVERROR(ENOMEM); if (rename(filename_src, filename_dst) < 0) return AVERROR(errno); @@ -212,6 +223,9 @@ static int file_open(URLContext *h, const char *filename, int flags) struct stat st; av_strstart(filename, "file:", &filename); + filename = ff_urldecode(filename, 0); + if(!filename) + return AVERROR(ENOMEM); if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) { access = O_CREAT | O_RDWR; diff --git a/libavformat/file.c b/libavformat/file.c index 6103c37b34..416e7a0b6b 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -21,6 +21,7 @@ #include "config_components.h" +#include "libavformat/urldecode.h" #include "libavutil/avstring.h" #include "libavutil/file_open.h" #include "libavutil/internal.h" @@ -142,7 +143,9 @@ static int file_check(URLContext *h, int mask) int ret = 0;