[FFmpeg-devel] [PATCH] avformat/file: fail for non-numerical arguments to pipe:
Marton Balint
cus at passwd.hu
Sun May 5 22:45:38 EEST 2024
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 at 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 at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avformat-file-fail-for-non-numerical-arguments-to-pi.patch
Type: text/x-patch
Size: 1897 bytes
Desc:
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240505/2abb4ab1/attachment.bin>
More information about the ffmpeg-devel
mailing list