From cb91de2a34765dc367df37c225041945ca9ece3c Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Fri, 31 Jan 2025 20:17:14 -0600 Subject: [PATCH] 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. --- filters/f_decoder_wrapper.c | 3 ++- options/m_option.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/filters/f_decoder_wrapper.c b/filters/f_decoder_wrapper.c index b2e9918757..6077baf9fe 100644 --- a/filters/f_decoder_wrapper.c +++ b/filters/f_decoder_wrapper.c @@ -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}, diff --git a/options/m_option.c b/options/m_option.c index fecde507e1..098128aa78 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -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); }