1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 08:37:59 +00:00

m_option: forbid non -1 negative values for video-aspect-override

Setting this to M_RANGE(-1, 10) meant that you could pass fractional
negative values without it being an error. This is, of course, nonsense.
-1 is the only special negative value with a meaning. Error out if we
get anything else by doing some additional parsing before we send it off
to parse_double which will then restrict the range to 0, 10 with these
changes. Note that this approach requires defval to be there which is
not the most extensible thing in the world. But there's literally only
two OPT_ASPECT type options out of the hundreds we have so not a big
deal. Ideally, this type should be OPT_CHOICE but with underlying
doubles but that's too much effort to implement cleanly.
This commit is contained in:
Dudemanguy 2025-01-31 20:17:14 -06:00
parent 16828aa952
commit cb91de2a34
2 changed files with 15 additions and 1 deletions

View File

@ -125,7 +125,8 @@ const struct m_sub_options dec_wrapper_conf = {
{"video-rotate", OPT_CHOICE(video_rotate, {"no", -1}),
.flags = UPDATE_IMGPAR, M_RANGE(0, 359)},
{"video-aspect-override", OPT_ASPECT(movie_aspect),
.flags = UPDATE_IMGPAR, M_RANGE(-1, 10)},
.flags = UPDATE_IMGPAR, M_RANGE(0, 10),
OPTDEF_DOUBLE(-1.0)},
{"video-aspect-method", OPT_CHOICE(aspect_method,
{"bitstream", 1}, {"container", 2}),
.flags = UPDATE_IMGPAR},

View File

@ -1116,6 +1116,19 @@ static int parse_double_aspect(struct mp_log *log, const m_option_t *opt,
VAL(dst) = 0.0;
return 1;
}
// Potentially allow -1 but forbid all other negative values.
if (opt->defval && *(double *)opt->defval == -1) {
struct bstr rest;
double val = bstrtod(param, &rest);
if (bstr_eatstart0(&rest, ":") || bstr_eatstart0(&rest, "/"))
val /= bstrtod(rest, &rest);
if (val == -1 && dst) {
VAL(dst) = -1.0;
return 1;
}
}
return parse_double(log, opt, name, param, dst);
}