summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-07-05 15:11:40 -0500
committerDudemanguy <random342@airmail.cc>2023-07-06 13:08:23 +0000
commitee69d99bd409d31ec35ee6f6be53db4ff29a55c9 (patch)
tree74d33ae41d88d1467b82fed966e803a3300607cd
parent48e0ee9979c2928edef813e64592217420dbd4a0 (diff)
downloadmpv-ee69d99bd409d31ec35ee6f6be53db4ff29a55c9.tar.bz2
mpv-ee69d99bd409d31ec35ee6f6be53db4ff29a55c9.tar.xz
various: correctly ignore cache files with --no-config
--no-config should prevent loading user files of any type: configs, cache, etc. For cache files, this case wasn't properly handled and it was assumed they would always get something. vo_gpu's shader cache actually already handles this, so it was left untouched. In theory, demuxer cache should never have this issue because saving it to disk is disabled by default (and likely that will never change), but go ahead and change it for consistency's sake. Fixes some segfaults with --no-config and various combinations of settings (particularly --vo=gpu-next).
-rw-r--r--DOCS/man/options.rst6
-rw-r--r--demux/cache.c5
-rw-r--r--video/out/gpu/lcms.c13
-rw-r--r--video/out/vo_gpu_next.c15
4 files changed, 25 insertions, 14 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index 6a08a2d5b6..da163b9d88 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -719,9 +719,9 @@ Program Behavior
Print version string and exit.
``--no-config``
- Do not load default configuration files. This prevents loading of both the
- user-level and system-wide ``mpv.conf`` and ``input.conf`` files. Other
- configuration files are blocked as well, such as resume playback files.
+ Do not load default configuration or any user files. This prevents loading of
+ both the user-level and system-wide ``mpv.conf`` and ``input.conf`` files. Other
+ user files are blocked as well, such as resume playback files and cache files.
.. note::
diff --git a/demux/cache.c b/demux/cache.c
index 08ac193cdf..106f53dbed 100644
--- a/demux/cache.c
+++ b/demux/cache.c
@@ -105,8 +105,11 @@ struct demux_cache *demux_cache_create(struct mpv_global *global,
} else {
cache_dir = mp_find_user_file(NULL, global, "cache", "");
}
- mp_mkdirp(cache_dir);
+ if (!cache_dir || !cache_dir[0])
+ goto fail;
+
+ mp_mkdirp(cache_dir);
cache->filename = mp_path_join(cache, cache_dir, "mpv-cache-XXXXXX.dat");
cache->fd = mp_mkostemps(cache->filename, 4, O_CLOEXEC);
if (cache->fd < 0) {
diff --git a/video/out/gpu/lcms.c b/video/out/gpu/lcms.c
index 7880f279e6..47ea160d8c 100644
--- a/video/out/gpu/lcms.c
+++ b/video/out/gpu/lcms.c
@@ -359,12 +359,13 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d,
cache_dir = mp_find_user_file(tmp, p->global, "cache", "");
}
- cache_file = talloc_strdup(tmp, "");
- for (int i = 0; i < sizeof(hash); i++)
- cache_file = talloc_asprintf_append(cache_file, "%02X", hash[i]);
- cache_file = mp_path_join(tmp, cache_dir, cache_file);
-
- mp_mkdirp(cache_dir);
+ if (cache_dir && cache_dir[0]) {
+ cache_file = talloc_strdup(tmp, "");
+ for (int i = 0; i < sizeof(hash); i++)
+ cache_file = talloc_asprintf_append(cache_file, "%02X", hash[i]);
+ cache_file = mp_path_join(tmp, cache_dir, cache_file);
+ mp_mkdirp(cache_dir);
+ }
}
// check cache
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c
index a8e8e1fae5..93cf4f54d6 100644
--- a/video/out/vo_gpu_next.c
+++ b/video/out/vo_gpu_next.c
@@ -1381,9 +1381,10 @@ static void wait_events(struct vo *vo, int64_t until_time_us)
static char *get_cache_file(struct priv *p)
{
+ char *file = NULL;
struct gl_video_opts *opts = p->opts_cache->opts;
if (!opts->shader_cache)
- return NULL;
+ goto done;
char *dir = opts->shader_cache_dir;
if (dir && dir[0]) {
@@ -1391,9 +1392,12 @@ static char *get_cache_file(struct priv *p)
} else {
dir = mp_find_user_file(NULL, p->global, "cache", "");
}
- char *file = mp_path_join(NULL, dir, "libplacebo.cache");
- mp_mkdirp(dir);
+ if (dir && dir[0]) {
+ file = mp_path_join(NULL, dir, "libplacebo.cache");
+ mp_mkdirp(dir);
+ }
talloc_free(dir);
+done:
return file;
}
@@ -1635,8 +1639,11 @@ static stream_t *icc_open_cache(struct priv *p, uint64_t sig, int flags)
} else {
cache_dir = mp_find_user_file(NULL, p->global, "cache", "");
}
- char *path = mp_path_join(NULL, cache_dir, cache_name);
+ if (!cache_dir || !cache_dir[0])
+ return NULL;
+
+ char *path = mp_path_join(NULL, cache_dir, cache_name);
stream_t *stream = NULL;
if (flags & STREAM_WRITE) {
mp_mkdirp(cache_dir);