* [FFmpeg-devel] [PATCH] avformat/file: fail for non-numerical arguments to pipe:
@ 2024-04-29 11:59 Nils Goroll
2024-05-05 19:45 ` Marton Balint
0 siblings, 1 reply; 2+ messages in thread
From: Nils Goroll @ 2024-04-29 11:59 UTC (permalink / raw)
To: ffmpeg-devel
Before this patch, the implementation of pipe: inputs/outputs would
silently fall back to stdin/stdout for any argument not successfully
parsed by strtol().
This patch introduces an explicit error for any non-numerical arguments,
which should avoid user confusion as in #10977.
New behavior:
$ cat /tmp/video.mkv | ./ffmpeg -i pipe:aa -acodec copy -vcodec copy -f matroska
pipe:1 | cat >/tmp/out.mkv
[pipe @ 0x5618c7bcf740] Non-numerical argument "aa" to pipe:
[in#0 @ 0x5618c7bced00] Error opening input: Invalid argument
Error opening input file pipe:aa.
Error opening input files: Invalid argument
Signed-off-by: Nils Goroll <nils.goroll@uplex.de>
---
libavformat/file.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/libavformat/file.c b/libavformat/file.c
index 0b7452bc20..317a769e32 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -437,18 +437,21 @@ static int pipe_open(URLContext *h, const char *filename,
int flags)
{
FileContext *c = h->priv_data;
int fd;
- char *final;
+ char *final = NULL;
if (c->fd < 0) {
av_strstart(filename, "pipe:", &filename);
- fd = strtol(filename, &final, 10);
- if((filename == final) || *final ) {/* No digits found, or something
like 10ab */
- if (flags & AVIO_FLAG_WRITE) {
- fd = 1;
- } else {
- fd = 0;
- }
+ if (*filename == '\0')
+ fd = (flags & AVIO_FLAG_WRITE) ? 1 : 0;
+ else
+ fd = strtol(filename, &final, 10);
+
+ if (final != NULL && *final != '\0') {
+ av_log(h, AV_LOG_ERROR,
+ "Non-numerical argument \"%s\" to pipe:\n",
+ filename);
+ return AVERROR(EINVAL);
}
c->fd = fd;
}
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/file: fail for non-numerical arguments to pipe:
2024-04-29 11:59 [FFmpeg-devel] [PATCH] avformat/file: fail for non-numerical arguments to pipe: Nils Goroll
@ 2024-05-05 19:45 ` Marton Balint
0 siblings, 0 replies; 2+ messages in thread
From: Marton Balint @ 2024-05-05 19:45 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 2454 bytes --]
On Mon, 29 Apr 2024, Nils Goroll wrote:
> Before this patch, the implementation of pipe: inputs/outputs would
> silently fall back to stdin/stdout for any argument not successfully
> parsed by strtol().
>
> This patch introduces an explicit error for any non-numerical arguments,
> which should avoid user confusion as in #10977.
>
> New behavior:
>
> $ cat /tmp/video.mkv | ./ffmpeg -i pipe:aa -acodec copy -vcodec copy -f
> matroska pipe:1 | cat >/tmp/out.mkv
>
> [pipe @ 0x5618c7bcf740] Non-numerical argument "aa" to pipe:
> [in#0 @ 0x5618c7bced00] Error opening input: Invalid argument
> Error opening input file pipe:aa.
> Error opening input files: Invalid argument
OK in principle, but the patch is a bit overcomplicated and is mixing
cosmetic and functional changes. See a simplifed version attached, will
apply that in a few days.
Thanks,
Marton
>
> Signed-off-by: Nils Goroll <nils.goroll@uplex.de>
> ---
> libavformat/file.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/libavformat/file.c b/libavformat/file.c
> index 0b7452bc20..317a769e32 100644
> --- a/libavformat/file.c
> +++ b/libavformat/file.c
> @@ -437,18 +437,21 @@ static int pipe_open(URLContext *h, const char
> *filename, int flags)
> {
> FileContext *c = h->priv_data;
> int fd;
> - char *final;
> + char *final = NULL;
> if (c->fd < 0) {
> av_strstart(filename, "pipe:", &filename);
> - fd = strtol(filename, &final, 10);
> - if((filename == final) || *final ) {/* No digits found, or something
> like 10ab */
> - if (flags & AVIO_FLAG_WRITE) {
> - fd = 1;
> - } else {
> - fd = 0;
> - }
> + if (*filename == '\0')
> + fd = (flags & AVIO_FLAG_WRITE) ? 1 : 0;
> + else
> + fd = strtol(filename, &final, 10);
> +
> + if (final != NULL && *final != '\0') {
> + av_log(h, AV_LOG_ERROR,
> + "Non-numerical argument \"%s\" to pipe:\n",
> + filename);
> + return AVERROR(EINVAL);
> }
> c->fd = fd;
> }
> --
> 2.39.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch; name=0001-avformat-file-fail-for-non-numerical-arguments-to-pi.patch, Size: 1897 bytes --]
From 1e65aa9e14cc66acc506bc7f41903a76627327f7 Mon Sep 17 00:00:00 2001
From: Marton Balint <cus@passwd.hu>
Date: Sun, 5 May 2024 21:31:47 +0200
Subject: [PATCH] avformat/file: fail for non-numerical arguments to pipe:
Before this patch, the implementation of pipe: inputs/outputs would
silently fall back to stdin/stdout for any argument not successfully
parsed by strtol().
This patch introduces an explicit error for any non-numerical arguments,
which should avoid user confusion as in #10977.
New behavior:
$ cat /tmp/video.mkv | ./ffmpeg -i pipe:aa -acodec copy -vcodec copy -f matroska pipe:1 | cat >/tmp/out.mkv
[pipe @ 0x5618c7bcf740] Non-numerical argument "aa" to pipe:
[in#0 @ 0x5618c7bced00] Error opening input: Invalid argument
Error opening input file pipe:aa.
Error opening input files: Invalid argument
Based on the patch of Nils Goroll <nils.goroll@uplex.de>.
Signed-off-by: Marton Balint <cus@passwd.hu>
---
libavformat/file.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libavformat/file.c b/libavformat/file.c
index 0b7452bc20..0ed4cff266 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -442,13 +442,16 @@ static int pipe_open(URLContext *h, const char *filename, int flags)
if (c->fd < 0) {
av_strstart(filename, "pipe:", &filename);
- fd = strtol(filename, &final, 10);
- if((filename == final) || *final ) {/* No digits found, or something like 10ab */
+ if (!*filename) {
if (flags & AVIO_FLAG_WRITE) {
fd = 1;
} else {
fd = 0;
}
+ } else {
+ fd = strtol(filename, &final, 10);
+ if (*final) /* No digits found, or something like 10ab */
+ return AVERROR(EINVAL);
}
c->fd = fd;
}
--
2.35.3
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-05 19:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 11:59 [FFmpeg-devel] [PATCH] avformat/file: fail for non-numerical arguments to pipe: Nils Goroll
2024-05-05 19:45 ` Marton Balint
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git