mirror of
https://github.com/mpv-player/mpv
synced 2025-02-01 12:42:04 +00:00
various: add missing checks for directory streams
All of this code opens a stream and expects to read stuff from a file. But streams can also be directories and that has to be handled.
This commit is contained in:
parent
b69b58a12a
commit
54c755b08d
@ -67,7 +67,7 @@ static mf_t *open_mf_pattern(void *talloc_ctx, struct demuxer *d, char *filename
|
||||
if (filename[0] == '@') {
|
||||
struct stream *s = stream_create(filename + 1,
|
||||
d->stream_origin | STREAM_READ, d->cancel, d->global);
|
||||
if (s) {
|
||||
if (s && !s->is_directory) {
|
||||
while (1) {
|
||||
char buf[512];
|
||||
int len = stream_read_peek(s, buf, sizeof(buf));
|
||||
@ -95,6 +95,7 @@ static mf_t *open_mf_pattern(void *talloc_ctx, struct demuxer *d, char *filename
|
||||
|
||||
goto exit_mf;
|
||||
}
|
||||
free_stream(s);
|
||||
mp_info(log, "%s is not indirect filelist\n", filename + 1);
|
||||
}
|
||||
|
||||
|
@ -1418,7 +1418,7 @@ static bool parse_config_file(struct input_ctx *ictx, char *file)
|
||||
file = mp_get_user_path(tmp, ictx->global, file);
|
||||
|
||||
s = stream_create(file, STREAM_ORIGIN_DIRECT | STREAM_READ, NULL, ictx->global);
|
||||
if (!s) {
|
||||
if (!s || s->is_directory) {
|
||||
MP_ERR(ictx, "Can't open input config file %s.\n", file);
|
||||
goto done;
|
||||
}
|
||||
|
@ -271,8 +271,8 @@ int stream_dump(struct MPContext *mpctx, const char *source_filename)
|
||||
stream_t *stream = stream_create(source_filename,
|
||||
STREAM_ORIGIN_DIRECT | STREAM_READ,
|
||||
mpctx->playback_abort, mpctx->global);
|
||||
if (!stream)
|
||||
return -1;
|
||||
if (!stream || stream->is_directory)
|
||||
goto done;
|
||||
|
||||
int64_t size = stream_get_size(stream);
|
||||
|
||||
|
@ -848,9 +848,12 @@ struct bstr stream_read_file(const char *filename, void *talloc_ctx,
|
||||
STREAM_LESS_NOISE;
|
||||
stream_t *s = stream_create(filename, flags, NULL, global);
|
||||
if (s) {
|
||||
res = stream_read_complete(s, talloc_ctx, max_size);
|
||||
free_stream(s);
|
||||
if (s->is_directory)
|
||||
mp_err(s->log, "Failed to open %s (not a file).\n", filename);
|
||||
else
|
||||
res = stream_read_complete(s, talloc_ctx, max_size);
|
||||
}
|
||||
free_stream(s);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,11 @@ static int open2(struct stream *stream, const struct stream_open_args *args)
|
||||
for (int n = 0; n < list->num_streams; n++) {
|
||||
struct stream *sub = list->streams[n];
|
||||
|
||||
if (sub->is_directory) {
|
||||
MP_FATAL(stream, "Sub stream %d is a directory.\n", n);
|
||||
return STREAM_ERROR;
|
||||
}
|
||||
|
||||
int64_t size = stream_get_size(sub);
|
||||
if (n != list->num_streams - 1 && size < 0) {
|
||||
MP_WARN(stream, "Sub stream %d has unknown size.\n", n);
|
||||
|
@ -168,6 +168,10 @@ static int open_cb(struct archive *arch, void *priv)
|
||||
vol->mpa->primary_src->stream_origin,
|
||||
vol->mpa->primary_src->cancel,
|
||||
vol->mpa->primary_src->global);
|
||||
if (vol->src && vol->src->is_directory) {
|
||||
free_stream(vol->src);
|
||||
vol->src = NULL;
|
||||
}
|
||||
// We pretend that failure to open a stream means it was not found,
|
||||
// we assume in turn means that the volume doesn't exist (since
|
||||
// libarchive builds volumes as some sort of abstraction on top of its
|
||||
|
@ -157,7 +157,11 @@ static int open2(struct stream *stream, const struct stream_open_args *args)
|
||||
return inner_ret;
|
||||
}
|
||||
|
||||
if (!p->inner->seekable) {
|
||||
if (p->inner->is_directory) {
|
||||
MP_FATAL(stream, "Inner stream '%s' is a directory\n", p->inner->url);
|
||||
free_stream(p->inner);
|
||||
return STREAM_ERROR;
|
||||
} else if (!p->inner->seekable) {
|
||||
MP_FATAL(stream, "Non-seekable stream '%s' can't be used with 'slice://'\n", p->inner->url);
|
||||
free_stream(p->inner);
|
||||
return STREAM_ERROR;
|
||||
|
Loading…
Reference in New Issue
Block a user