mirror of https://github.com/mpv-player/mpv
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().
This commit is contained in:
parent
7a93a584fc
commit
ae23556b6f
|
@ -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)
|
stream_t *open_output_stream(const char *filename, struct mpv_global *global)
|
||||||
{
|
{
|
||||||
return stream_create(filename, STREAM_ORIGIN_DIRECT | STREAM_WRITE,
|
struct stream *s = stream_create(filename, STREAM_ORIGIN_DIRECT | STREAM_WRITE,
|
||||||
NULL, global);
|
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
|
// 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)
|
if (max_size <= 0 || max_size > STREAM_MAX_READ_SIZE)
|
||||||
abort();
|
abort();
|
||||||
|
if (s->is_directory)
|
||||||
|
return (struct bstr){NULL, 0};
|
||||||
|
|
||||||
int bufsize;
|
int bufsize;
|
||||||
int total_read = 0;
|
int total_read = 0;
|
||||||
|
|
Loading…
Reference in New Issue