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.
Unified · Split
| @@ -125,7 +125,8 @@ const struct m_sub_options dec_wrapper_conf = { · 124 unmodified lines | |||
| 125 | {"video-rotate", OPT_CHOICE(video_rotate, {"no", -1}), | 125 | {"video-rotate", OPT_CHOICE(video_rotate, {"no", -1}), |
| 126 | .flags = UPDATE_IMGPAR, M_RANGE(0, 359)}, | 126 | .flags = UPDATE_IMGPAR, M_RANGE(0, 359)}, |
| 127 | {"video-aspect-override", OPT_ASPECT(movie_aspect), | 127 | {"video-aspect-override", OPT_ASPECT(movie_aspect), |
| 128 | .flags = UPDATE_IMGPAR, M_RANGE(-1, 10)}, | 128 | .flags = UPDATE_IMGPAR, M_RANGE(0, 10), |
| 129 | OPTDEF_DOUBLE(-1.0)}, | ||
| 129 | {"video-aspect-method", OPT_CHOICE(aspect_method, | 130 | {"video-aspect-method", OPT_CHOICE(aspect_method, |
| 130 | {"bitstream", 1}, {"container", 2}), | 131 | {"bitstream", 1}, {"container", 2}), |
| 131 | .flags = UPDATE_IMGPAR}, | 132 | .flags = UPDATE_IMGPAR}, |
| @@ -1116,6 +1116,19 @@ static int parse_double_aspect(struct mp_log *log, const m_option_t *opt, · 1115 unmodified lines | |||
| 1116 | VAL(dst) = 0.0; | 1116 | VAL(dst) = 0.0; |
| 1117 | return 1; | 1117 | return 1; |
| 1118 | } | 1118 | } |
| 1119 | |||
| 1120 | // Potentially allow -1 but forbid all other negative values. | ||
| 1121 | if (opt->defval && *(double *)opt->defval == -1) { | ||
| 1122 | struct bstr rest; | ||
| 1123 | double val = bstrtod(param, &rest); | ||
| 1124 | if (bstr_eatstart0(&rest, ":") || bstr_eatstart0(&rest, "/")) | ||
| 1125 | val /= bstrtod(rest, &rest); | ||
| 1126 | if (val == -1 && dst) { | ||
| 1127 | VAL(dst) = -1.0; | ||
| 1128 | return 1; | ||
| 1129 | } | ||
| 1130 | } | ||
| 1131 | |||
| 1119 | return parse_double(log, opt, name, param, dst); | 1132 | return parse_double(log, opt, name, param, dst); |
| 1120 | } | 1133 | } |
| 1121 | 1134 | ||