Skip to content

Commit

Permalink
stream: disallow reading or writing to directories
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
sfan5 committed May 15, 2024
1 parent 7a93a58 commit ae23556
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions stream/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ae23556

Please sign in to comment.