[vlc-devel] [PATCH] sout: file: truncate path if too long
Rémi Denis-Courmont
remi at remlab.net
Mon Dec 16 15:26:25 CET 2019
Hi,
So if the user specifically requests a long file name on a system that supports it, you'll truncate anyway, and thus break scripts or third party apps that wrap VLC?
This makes no sense to me.
Le 16 décembre 2019 15:15:49 GMT+02:00, Thomas Guillem <thomas at gllm.fr> a écrit :
>This fixes sout chain fail when the input path/url is too long. This
>can easily
>happen when the source is a network url that can be longer than local
>pathes.
>---
> modules/access_output/file.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
>diff --git a/modules/access_output/file.c
>b/modules/access_output/file.c
>index c983e3a8f09..86fe032dd0b 100644
>--- a/modules/access_output/file.c
>+++ b/modules/access_output/file.c
>@@ -36,6 +36,8 @@
> #include <errno.h>
> #include <sys/stat.h>
> #include <unistd.h>
>+#include <limits.h>
>+#include <string.h>
> #ifdef __OS2__
> # include <io.h> /* setmode() */
> #endif
>@@ -298,6 +300,36 @@ static int Open( vlc_object_t *p_this )
> if (var_GetBool (p_access, SOUT_CFG_PREFIX"sync"))
> flags |= O_SYNC;
> #endif
>+
>+#ifndef NAME_MAX
>+ #ifdef (MAX_PATH)
>+ #define NAME_MAX MAX_PATH /* win32 */
>+ #else
>+ #define NAME_MAX 256
>+ #endif
>+#endif
>+ /* Check if the path need to be truncated */
>+ size_t path_len = strlen(path);
>+ if (path_len > NAME_MAX)
>+ {
>+ /* Allocate the buf if needed since p_access->psz_path is
>const */
>+ if (path == p_access->psz_path)
>+ {
>+ buf = strdup(path);
>+ if (!buf)
>+ return VLC_ENOMEM;
>+ path = buf;
>+ }
>+
>+ /* Don't loose the extension if any */
>+ const char *ext = strrchr(path, '.');
>+ size_t ext_len = ext ? strlen(ext) : 0;
>+ if (ext && ext_len <= 4)
>+ strcpy(&buf[NAME_MAX - ext_len - 1], ext);
>+ else
>+ buf[NAME_MAX] = 0;
>+ }
>+
> do
> {
> fd = vlc_open (path, flags, 0666);
>--
>2.20.1
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel
--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20191216/1fa97975/attachment.html>
More information about the vlc-devel
mailing list