From ae23556b6fe07c215d5f443bd5765958cf700f0f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 13 May 2024 21:27:54 +0200 Subject: [PATCH] stream: disallow reading or writing to directories Reading an entire file is a common operation, meanwhile stream_file will happily open a directory. This doesn't match well. Analogously for open_output_stream(). --- stream/stream.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stream/stream.c b/stream/stream.c index 56313502c3..97d3f4352d 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -471,8 +471,13 @@ struct stream *stream_create(const char *url, int flags, stream_t *open_output_stream(const char *filename, struct mpv_global *global) { - return stream_create(filename, STREAM_ORIGIN_DIRECT | STREAM_WRITE, - NULL, global); + struct stream *s = stream_create(filename, STREAM_ORIGIN_DIRECT | STREAM_WRITE, + NULL, global); + if (s && s->is_directory) { + free_stream(s); + s = NULL; + } + return s; } // Read function bypassing the local stream buffer. This will not write into @@ -804,6 +809,8 @@ struct bstr stream_read_complete(struct stream *s, void *talloc_ctx, { if (max_size <= 0 || max_size > STREAM_MAX_READ_SIZE) abort(); + if (s->is_directory) + return (struct bstr){NULL, 0}; int bufsize; int total_read = 0;